You are here

function _fillpdf_add_publish_completed_orders_permission in FillPDF 7.2

Same name and namespace in other branches
  1. 7 fillpdf.install \_fillpdf_add_publish_completed_orders_permission()
3 calls to _fillpdf_add_publish_completed_orders_permission()
fillpdf_install in ./fillpdf.install
Implements hook_install().
fillpdf_modules_enabled in ./fillpdf.module
Implements hook_modules_enabled().
fillpdf_update_7201 in ./fillpdf.install
Let all roles use completed order data to fill PDFs by default, assuming they otherwise are allowed.

File

./fillpdf.install, line 111
Install

Code

function _fillpdf_add_publish_completed_orders_permission() {

  // Allow anyone to fill Completed orders by default, subject to having other
  // required permissions such as view own orders. Only do this once, ever.
  if (module_exists('uc_order') && module_exists('user') && !variable_get('fillpdf_uc_order_initialized', FALSE)) {
    $order_statuses = uc_order_status_list();
    $completed_status = NULL;
    foreach ($order_statuses as $order_status) {
      if ($order_status['id'] == 'completed') {
        $completed_status = $order_status['id'];
      }
    }
    if ($completed_status) {
      $roles = user_roles();
      foreach ($roles as $rid => $title) {
        user_role_grant_permissions($rid, array(
          "publish {$completed_status} order data",
        ));
      }
      variable_set('fillpdf_uc_order_initialized', TRUE);
      $fillpdf_permissions = fillpdf_permission();
      drupal_set_message("FillPDF has automatically given all the roles the {$fillpdf_permissions[<span class="php-string">"publish {$completed_status} order data"</span>][<span class="php-string">'title'</span>]} permission. You can disable this from the Permissions page. This is the only time FillPDF will do this automatically.");
    }
  }
}