Beispiel #1
0
 public function getThemeDirectoryPath($pb_use_default = false)
 {
     if ($this->config->get('always_use_default_theme')) {
         $pb_use_default = true;
     }
     if (!$pb_use_default && $this->isLoggedIn()) {
         $vs_theme = $this->user->getPreference('ui_theme');
     } else {
         $vs_theme = $this->config->get('theme');
         // default theme
     }
     return $this->config->get('themes_directory') . '/' . $vs_theme;
 }
 public function DownloadUserReport()
 {
     $vs_download_format = $this->request->getParameter("download_format", pString);
     if (!$vs_download_format) {
         $vs_download_format = "tab";
     }
     $this->view->setVar("download_format", $vs_download_format);
     switch ($vs_download_format) {
         default:
         case "tab":
             $this->view->setVar("file_extension", "txt");
             $this->view->setVar("mimetype", "text/plain");
             $vs_delimiter_col = "\t";
             $vs_delimiter_row = "\n";
             break;
             # -----------------------------------
         # -----------------------------------
         case "csv":
             $this->view->setVar("file_extension", "txt");
             $this->view->setVar("mimetype", "text/plain");
             $vs_delimiter_col = ",";
             $vs_delimiter_row = "\n";
             break;
             # -----------------------------------
     }
     $o_db = new Db();
     $t_user = new ca_users();
     $va_fields = array("lname", "fname", "email", "user_name", "userclass", "active", "last_login");
     $va_profile_prefs = $t_user->getValidPreferences('profile');
     $va_profile_prefs_labels = array();
     foreach ($va_profile_prefs as $vs_pref) {
         $va_pref_info = $t_user->getPreferenceInfo($vs_pref);
         $va_profile_prefs_labels[$vs_pref] = $va_pref_info["label"];
     }
     $qr_users = $o_db->query("SELECT * FROM ca_users ORDER BY user_id DESC");
     if ($qr_users->numRows()) {
         $va_rows = array();
         # --- headings
         $va_row = array();
         # --- headings for field values
         foreach ($va_fields as $vs_field) {
             switch ($vs_field) {
                 case "last_login":
                     $va_row[] = _t("Last login");
                     break;
                     # --------------------
                 # --------------------
                 default:
                     $va_row[] = $t_user->getDisplayLabel("ca_users." . $vs_field);
                     break;
                     # --------------------
             }
         }
         # --- headings for profile prefs
         foreach ($va_profile_prefs_labels as $vs_pref => $vs_pref_label) {
             $va_row[] = $vs_pref_label;
         }
         $va_rows[] = join($vs_delimiter_col, $va_row);
         reset($va_fields);
         reset($va_profile_prefs_labels);
         $o_tep = new TimeExpressionParser();
         while ($qr_users->nextRow()) {
             $va_row = array();
             # --- fields
             foreach ($va_fields as $vs_field) {
                 switch ($vs_field) {
                     case "userclass":
                         $va_row[] = $t_user->getChoiceListValue($vs_field, $qr_users->get("ca_users." . $vs_field));
                         break;
                         # -----------------------
                     # -----------------------
                     case "active":
                         $va_row[] = $qr_users->get("ca_users." . $vs_field) == 1 ? _t("active") : _t("not active");
                         break;
                         # -----------------------
                     # -----------------------
                     case "last_login":
                         //if (!is_array($va_vars = $qr_users->getVars('vars'))) { $va_vars = array(); }
                         if (!is_array($va_vars = $qr_users->getVars('volatile_vars'))) {
                             $va_vars = array();
                         }
                         if ($va_vars['last_login'] > 0) {
                             $o_tep->setUnixTimestamps($va_vars['last_login'], $va_vars['last_login']);
                             $va_row[] = $o_tep->getText();
                         } else {
                             $va_row[] = "-";
                         }
                         break;
                         # -----------------------
                     # -----------------------
                     default:
                         if ($vs_download_format == "csv") {
                             $va_row[] = str_replace(",", "-", $qr_users->get("ca_users." . $vs_field));
                         } else {
                             $va_row[] = $qr_users->get("ca_users." . $vs_field);
                         }
                         break;
                         # -----------------------
                 }
             }
             # --- profile prefs
             foreach ($va_profile_prefs_labels as $vs_pref => $vs_pref_label) {
                 $t_user->load($qr_users->get("ca_users.user_id"));
                 $va_row[] = $t_user->getPreference($vs_pref);
             }
             $va_rows[] = join($vs_delimiter_col, $va_row);
         }
         $vs_file_contents = join($vs_delimiter_row, $va_rows);
         $this->view->setVar("file_contents", $vs_file_contents);
         return $this->render('user_report.php');
     } else {
         $this->notification->addNotification(_t("There are no users"), __NOTIFICATION_TYPE_INFO__);
         $this->ListUsers();
         return;
     }
 }
 /**
  * Return user profile values for specified user
  */
 public function GetUserProfileInfo()
 {
     if (!$this->request->user->canDoAction('can_manage_clients')) {
         return null;
     }
     $pn_user_id = $this->request->getParameter('user_id', pInteger);
     $t_user = new ca_users($pn_user_id);
     $va_profile_prefs = $t_user->getValidPreferences('profile');
     if (is_array($va_profile_prefs) && sizeof($va_profile_prefs)) {
         $va_elements = array();
         foreach ($va_profile_prefs as $vs_pref) {
             $va_pref_info = $t_user->getPreferenceInfo($vs_pref);
             $va_elements[str_replace('user_profile_', '', $vs_pref)] = array($t_user->getPreference($vs_pref));
         }
         $this->view->setVar("profile_values", $va_elements);
     }
     $this->view->setVar("user_id", $pn_user_id);
     $this->render('ajax_user_profile_info_json.php');
 }
 public function Save()
 {
     // Field to user profile preference mapping
     $va_mapping = array('billing_organization' => 'user_profile_organization', 'billing_address1' => 'user_profile_address1', 'billing_address2' => 'user_profile_address2', 'billing_city' => 'user_profile_city', 'billing_zone' => 'user_profile_state', 'billing_postal_code' => 'user_profile_postalcode', 'billing_country' => 'user_profile_country', 'billing_phone' => 'user_profile_phone', 'billing_fax' => 'user_profile_fax', 'shipping_organization' => 'user_profile_organization', 'shipping_address1' => 'user_profile_address1', 'shipping_address2' => 'user_profile_address2', 'shipping_city' => 'user_profile_city', 'shipping_zone' => 'user_profile_state', 'shipping_postal_code' => 'user_profile_postalcode', 'shipping_country' => 'user_profile_country', 'shipping_phone' => 'user_profile_phone', 'shipping_fax' => 'user_profile_fax');
     $va_errors = array();
     $va_failed_insert_list = array();
     $va_fields = $this->opt_order->getFormFields();
     foreach ($va_fields as $vs_f => $va_field_info) {
         switch ($vs_f) {
             case 'transaction_id':
                 // noop
                 break;
             default:
                 if (isset($_REQUEST[$vs_f])) {
                     if (!$this->opt_order->set($vs_f, $this->request->getParameter($vs_f, pString))) {
                         $va_errors[$vs_f] = $this->opt_order->errors();
                     }
                 }
                 break;
         }
     }
     // Set additional fees for order
     $va_fees = $this->opo_client_services_config->getAssoc('additional_order_fees');
     if (is_array($va_fees)) {
         if (!is_array($va_fee_values = $this->opt_order->get('additional_fees'))) {
             $va_fee_values = array();
         }
         foreach ($va_fees as $vs_code => $va_info) {
             $va_fee_values[$vs_code] = (double) $this->request->getParameter("additional_fee_{$vs_code}", pString);
         }
         $this->opt_order->set('additional_fees', $va_fee_values);
     }
     $this->opt_order->setMode(ACCESS_WRITE);
     if ($this->opt_order->getPrimaryKey()) {
         $this->opt_order->update();
         $vn_transaction_id = $this->opt_order->get('transaction_id');
     } else {
         // Set transaction
         if (!($vn_transaction_id = $this->request->getParameter('transaction_id', pInteger))) {
             if (!($vn_user_id = $this->request->getParameter('transaction_user_id', pInteger))) {
                 if ($vs_user_name = $this->request->getParameter('billing_email', pString)) {
                     // Try to create user in-line
                     $t_user = new ca_users();
                     if ($t_user->load(array('user_name' => $vs_user_name))) {
                         if ($t_user->get('active') == 1) {
                             // user is active - if not active don't use
                             if ($t_user->get('userclass') == 255) {
                                 // user is deleted
                                 $t_user->setMode(ACCESS_WRITE);
                                 $t_user->set('userclass', 1);
                                 // 1=public user (no back-end login)
                                 $t_user->update();
                                 if ($t_user->numErrors()) {
                                     $this->notification->addNotification(_t('Errors occurred when undeleting user: %1', join('; ', $t_user->getErrors())), __NOTIFICATION_TYPE_ERROR__);
                                 } else {
                                     $vn_user_id = $t_user->getPrimaryKey();
                                 }
                             } else {
                                 $vn_user_id = $t_user->getPrimaryKey();
                             }
                         } else {
                             $t_user->setMode(ACCESS_WRITE);
                             $t_user->set('active', 1);
                             $t_user->set('userclass', 1);
                             // 1=public user (no back-end login)
                             $t_user->update();
                             if ($t_user->numErrors()) {
                                 $this->notification->addNotification(_t('Errors occurred when reactivating user: %1', join('; ', $t_user->getErrors())), __NOTIFICATION_TYPE_ERROR__);
                             } else {
                                 $vn_user_id = $t_user->getPrimaryKey();
                             }
                         }
                     } else {
                         $t_user->setMode(ACCESS_WRITE);
                         $t_user->set('user_name', $vs_user_name);
                         $t_user->set('password', $vs_password = substr(md5(uniqid(microtime())), 0, 6));
                         $t_user->set('userclass', 1);
                         // 1=public user (no back-end login)
                         $t_user->set('fname', $vs_fname = $this->request->getParameter('billing_fname', pString));
                         $t_user->set('lname', $vs_lname = $this->request->getParameter('billing_lname', pString));
                         $t_user->set('email', $vs_user_name);
                         $t_user->insert();
                         if ($t_user->numErrors()) {
                             $this->notification->addNotification(_t('Errors occurred when creating new user: %1', join('; ', $t_user->getErrors())), __NOTIFICATION_TYPE_ERROR__);
                         } else {
                             $vn_user_id = $t_user->getPrimaryKey();
                             $this->notification->addNotification(_t('Created new client login for <em>%1</em>. Login name is <em>%2</em> and password is <em>%3</em>', $vs_fname . ' ' . $vs_lname, $vs_user_name, $vs_password), __NOTIFICATION_TYPE_INFO__);
                             // Create related entity?
                         }
                     }
                 }
             }
             if ($vn_user_id) {
                 // try to create transaction
                 $t_trans = new ca_commerce_transactions();
                 $t_trans->setMode(ACCESS_WRITE);
                 $t_trans->set('user_id', $vn_user_id);
                 $t_trans->set('short_description', "Created on " . date("c"));
                 $t_trans->set('set_id', null);
                 $t_trans->insert();
                 if ($t_trans->numErrors()) {
                     $this->notification->addNotification(_t('Errors occurred when creating commerce transaction: %1', join('; ', $t_trans->getErrors())), __NOTIFICATION_TYPE_ERROR__);
                 } else {
                     $vn_transaction_id = $t_trans->getPrimaryKey();
                 }
             } else {
                 $this->notification->addNotification(_t('You must specify a client'), __NOTIFICATION_TYPE_ERROR__);
                 $va_errors['general'][] = new Error(1100, _t('You must specify a client'), 'CheckOutController->Save()', false, false, false);
             }
         }
         $this->opt_order->set('transaction_id', $vn_transaction_id);
         if ($vn_transaction_id) {
             $this->opt_order->set('order_type', 'L');
             // L = loan (as opposed to 'O' for sales orders)
             $this->opt_order->set('order_status', 'OPEN');
             $this->opt_order->insert();
             $this->request->setParameter('order_id', $x = $this->opt_order->getPrimaryKey());
         }
     }
     if ($vn_transaction_id) {
         // set user profile if not already set
         $t_trans = new ca_commerce_transactions($vn_transaction_id);
         $t_user = new ca_users($t_trans->get('user_id'));
         $t_user->setMode(ACCESS_WRITE);
         foreach ($va_mapping as $vs_field => $vs_pref) {
             if (!strlen($t_user->getPreference($vs_pref))) {
                 $t_user->setPreference($vs_pref, $this->opt_order->get($vs_field));
             }
         }
         $t_user->update();
         $va_additional_fee_codes = $this->opo_client_services_config->getAssoc('additional_loan_fees');
         // Look for newly added items
         $vn_items_added = 0;
         $vn_item_errors = 0;
         $vs_errors = '';
         foreach ($_REQUEST as $vs_k => $vs_v) {
             if (preg_match("!^item_list_idnew_([\\d]+)\$!", $vs_k, $va_matches)) {
                 if ($vn_object_id = (int) $vs_v) {
                     // add item to order
                     $va_values = array();
                     foreach ($_REQUEST as $vs_f => $vs_value) {
                         if (preg_match("!^item_list_([A-Za-z0-9_]+)_new_" . $va_matches[1] . "\$!", $vs_f, $va_matches2)) {
                             $va_values[$va_matches2[1]] = $vs_value;
                         }
                     }
                     // Set additional fees
                     //
                     $va_fee_values = array();
                     foreach ($va_additional_fee_codes as $vs_code => $va_info) {
                         $va_fee_values[$vs_code] = $_REQUEST['additional_order_item_fee_' . $vs_code . '_new_' . $va_matches[1]];
                     }
                     $t_item = $this->opt_order->addItem($vn_object_id, $va_values, array('additional_fees' => $va_fee_values));
                     if ($t_item && $t_item->getPrimaryKey()) {
                         $vn_items_added++;
                     } else {
                         if ($this->opt_order->numErrors()) {
                             $t_object = new ca_objects($vn_object_id);
                             $this->notification->addNotification(_t('Could not check-out item <em>%1</em> (%2) due to errors: %3', $t_object->get('ca_objects.preferred_labels.name'), $t_object->get('idno'), join("; ", $this->opt_order->getErrors())), __NOTIFICATION_TYPE_ERROR__);
                             $vn_item_errors++;
                             $va_fee_values_proc = array();
                             foreach ($va_fee_values as $vs_k => $vs_v) {
                                 $va_fee_values_proc['ADDITIONAL_FEE_' . $vs_k] = $vs_v;
                             }
                             $va_failed_insert_list[] = array_merge($va_values, $va_fee_values_proc, array('autocomplete' => $_REQUEST['item_list_autocompletenew_' . $va_matches[1]], 'id' => $vn_object_id));
                         }
                     }
                 }
             }
         }
         if (!$this->opt_order->numErrors() && $vn_items_added) {
             $this->notification->addNotification(_t('Checked out %1 %2 for %3 (order %4)', $vn_items_added, $vn_items_added == 1 ? _t('item') : _t('items'), $t_user->get('fname') . ' ' . $t_user->get('lname'), $this->opt_order->getOrderNumber()), __NOTIFICATION_TYPE_INFO__);
             $this->opt_order->set('order_status', 'PROCESSED');
             $this->opt_order->update();
             $this->opt_order = new ca_commerce_orders();
             $this->request->setParameter('order_id', null);
             $this->view->setVar('t_order', $this->opt_order);
             $this->view->setVar('order_id', $this->opt_order->getPrimaryKey());
             $this->view->setVar('t_item', $this->opt_order);
         } else {
             if ($vn_items_added == 0 && $this->opt_order->numErrors() == 0) {
                 $vs_errors = _t('No items were specified');
             } else {
                 if ($vn_item_errors == 0) {
                     $vs_errors = join('; ', $this->opt_order->getErrors());
                 }
             }
             if ($vs_errors) {
                 $va_errors['general'] = $this->opt_order->errors();
                 $this->notification->addNotification(_t('Errors occurred: %1', $vs_errors), __NOTIFICATION_TYPE_ERROR__);
             }
         }
     }
     $this->view->setVar('errors', $va_errors);
     $this->view->setVar('failed_insert_list', $va_failed_insert_list);
     $this->Index();
 }
Beispiel #5
0
 /**
  * Duplicate all items in this set
  * @param int $pn_user_id
  * @param array $pa_options
  * @return ca_sets|bool
  */
 public function duplicateItemsInSet($pn_user_id, $pa_options = array())
 {
     if (!$this->getPrimaryKey()) {
         return false;
     }
     if ($this->getItemCount() < 1) {
         return false;
     }
     $t_user = new ca_users($pn_user_id);
     if (!$t_user->getPrimaryKey()) {
         return false;
     }
     // we need a user for duplication
     global $g_ui_locale_id;
     if (caGetOption('addToCurrentSet', $pa_options, false)) {
         $t_set_to_add_dupes_to = $this;
     } else {
         // create new set for dupes
         $t_set_to_add_dupes_to = new ca_sets();
         $t_set_to_add_dupes_to->set('type_id', $this->get('type_id'));
         $t_set_to_add_dupes_to->set('table_num', $this->get('table_num'));
         $t_set_to_add_dupes_to->set('user_id', $this->get('user_id'));
         $t_set_to_add_dupes_to->set('set_code', $this->get('set_code') . '-' . _t('dupes'));
         $t_set_to_add_dupes_to->setMode(ACCESS_WRITE);
         $t_set_to_add_dupes_to->insert();
         if (!$t_set_to_add_dupes_to->getPrimaryKey()) {
             $this->errors = $t_set_to_add_dupes_to->errors;
             return false;
         }
         $t_set_to_add_dupes_to->addLabel(array('name' => $this->getLabelForDisplay() . ' ' . _t('[Duplicates]')), $g_ui_locale_id, null, true);
     }
     $va_items = array_keys($this->getItemRowIDs());
     $va_dupes = array();
     foreach ($va_items as $vn_row_id) {
         /** @var BundlableLabelableBaseModelWithAttributes $t_instance */
         $t_instance = $this->getAppDatamodel()->getInstance($this->get('table_num'));
         if (!$t_user->canDoAction('can_duplicate_' . $t_instance->tableName())) {
             $this->postError(2580, _t('You do not have permission to duplicate these items'), 'ca_sets->duplicateItemsInSet()');
             return false;
         }
         if (!$t_instance->load($vn_row_id)) {
             continue;
         }
         // let's dupe
         $t_dupe = $t_instance->duplicate(array('user_id' => $pn_user_id, 'duplicate_nonpreferred_labels' => $t_user->getPreference($t_instance->tableName() . '_duplicate_nonpreferred_labels'), 'duplicate_attributes' => $t_user->getPreference($t_instance->tableName() . '_duplicate_attributes'), 'duplicate_relationships' => $t_user->getPreference($t_instance->tableName() . '_duplicate_relationships'), 'duplicate_media' => $t_user->getPreference($t_instance->tableName() . '_duplicate_media'), 'duplicate_subitems' => $t_user->getPreference($t_instance->tableName() . '_duplicate_subitems')));
         if ($t_dupe instanceof BaseModel) {
             $va_dupes[] = $t_dupe->getPrimaryKey();
         }
     }
     $t_set_to_add_dupes_to->addItems($va_dupes);
     return $t_set_to_add_dupes_to;
 }