/** * */ public function CreateNewOrderFromCommunication() { if ($pn_communication_id = $this->request->getParameter('communication_id', pInteger)) { $t_comm = new ca_commerce_communications($pn_communication_id); if (!$t_comm->getPrimaryKey()) { $this->notification->addNotification(_t('Invalid message'), __NOTIFICATION_TYPE_ERROR__); $this->CustomerInfo(); return; } $t_trans = new ca_commerce_transactions($t_comm->get('transaction_id')); if (!$t_trans->getPrimaryKey()) { $this->notification->addNotification(_t('Message is not associated with a transaction'), __NOTIFICATION_TYPE_ERROR__); $this->CustomerInfo(); return; } $t_user = new ca_users($t_trans->get('user_id')); $this->opt_order->setMode(ACCESS_WRITE); $this->opt_order->set('transaction_id', $t_trans->getPrimaryKey()); if ($t_user->getPrimaryKey()) { $this->opt_order->set('billing_fname', $t_user->get('fname')); $this->opt_order->set('billing_lname', $t_user->get('lname')); $this->opt_order->set('billing_email', $t_user->get('email')); $this->opt_order->set('shipping_fname', $t_user->get('fname')); $this->opt_order->set('shipping_lname', $t_user->get('lname')); $this->opt_order->set('shipping_email', $t_user->get('email')); // Pre-populate order with user's profile address $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'); foreach ($va_mapping as $vs_field => $vs_pref) { $this->opt_order->set($vs_field, $t_user->getPreference($vs_pref)); } } $this->opt_order->set('order_type', 'L'); // L=loan $this->opt_order->insert(); $this->request->setParameter('order_id', $this->opt_order->getPrimaryKey()); if (!$this->opt_order->numErrors()) { $this->notification->addNotification(_t('Saved changes'), __NOTIFICATION_TYPE_INFO__); // Add items $t_set = new ca_sets($t_trans->get('set_id')); if ($t_set->getPrimaryKey()) { $va_items = $t_set->getItems(); foreach ($va_items as $va_item_list) { foreach ($va_item_list as $vn_i => $va_item) { if (!is_array($va_item['selected_services'])) { //$va_item['selected_services'] = array('DIGITAL_COPY'); // TODO: make default configurable } foreach ($va_item['selected_services'] as $vs_service) { if ($t_item = $this->opt_order->addItem($va_item['row_id'], array('service' => $vs_service), array('representations_ids' => is_array($va_item['selected_representations']) && sizeof($va_item['selected_representations']) ? $va_item['selected_representations'] : null))) { $t_item->updateFee(); } } } } // Delete originating set if configured to do so if ($this->opo_client_services_config->get('set_disposal_policy') == 'DELETE_WHEN_ORDER_CREATED') { $t_set->setMode(ACCESS_WRITE); $t_set->delete(true); } } } else { $va_errors['general'] = $this->opt_order->errors(); $this->notification->addNotification(_t('Errors occurred: %1', join('; ', $this->opt_order->getErrors())), __NOTIFICATION_TYPE_ERROR__); } $this->view->setVar('errors', $va_errors); } $this->OrderOverview(); }
public function SendReply() { $pn_transaction_id = $this->request->getParameter('transaction_id', pInteger); $t_trans = new ca_commerce_transactions($pn_transaction_id); //$this->view->setVar('communication_id', $pn_communication_id); $this->view->setVar('transaction_id', $pn_transaction_id); if ($t_trans->haveAccessToTransaction($this->request->getUserID())) { $t_trans->sendInstitutionMessage('L', $this->request->getParameter('subject', pString), $this->request->getParameter('message', pString), $this->request->getUserID()); $this->Index(); } else { $this->view->setVar('transaction', null); $this->render('reply_to_communication_html.php'); } }
/** * */ public function haveAccessToMessage($pn_user_id, $pn_communication_id = null) { $t_user = new ca_users($pn_user_id); if ($t_user->canDoAction('can_manage_clients')) { return true; } if ($pn_communication_id) { $t_comm = new ca_commerce_communications($pn_communication_id); if (!$t_comm->getPrimaryKey()) { return false; } } else { $t_comm = $this; } $t_trans = new ca_commerce_transactions($t_comm->get('transaction_id')); if ($t_trans->getPrimaryKey()) { if ($t_trans->get('user_id') == $pn_user_id) { return true; } } return false; }
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(); }
/** * */ public function SendReply() { $pn_set_id = $this->request->getParameter('set_id', pInteger); $o_purifier = new HTMLPurifier(); $t_trans = new ca_commerce_transactions(); if (!$t_trans->load(array('set_id' => $pn_set_id))) { $t_trans->setMode(ACCESS_WRITE); $t_trans->set('user_id', $this->request->getUserID()); $t_trans->set('short_description', "Transaction for set {$pn_set_id}"); $t_trans->set('set_id', $pn_set_id); $t_trans->insert(); } $t_comm = $t_trans->sendUserMessage('O', $o_purifier->purify($this->request->getParameter('subject', pString)), $o_purifier->purify($this->request->getParameter('message', pString)), $this->request->getUserID()); if ($t_comm->numErrors() == 0) { $this->notification->addNotification(_t("Your inquiry was sent. You will receive a response through this web site and by email soon."), __NOTIFICATION_TYPE_INFO__); } else { $this->notification->addNotification(_t("Your inquiry was not sent due to errors: %1", join("; ", $t_comm->getErrors())), __NOTIFICATION_TYPE_ERROR__); } $this->index(); }
/** * Check if order is owned by user * * @param int $pn_user_id The user_id * @return bool */ public function userHasAccessToOrder($pn_user_id) { if (!$this->getPrimaryKey()) { return null; } $t_trans = new ca_commerce_transactions($this->get('transaction_id')); if (!$t_trans->getPrimaryKey()) { return null; } if ((int) $t_trans->get('user_id') === (int) $pn_user_id) { return true; } return false; }
/** * */ public function SendReply() { $pn_order_id = $this->request->getParameter('order_id', pInteger); $pn_transaction_id = $this->request->getParameter('transaction_id', pInteger); $o_purifier = new HTMLPurifier(); $t_trans = new ca_commerce_transactions(); if ($t_trans->load($pn_transaction_id)) { $t_trans->sendUserMessage('O', $o_purifier->purify($this->request->getParameter('subject', pString)), $o_purifier->purify($this->request->getParameter('message', pString)), $this->request->getUserID()); $this->notification->addNotification(_t("Sent message"), __NOTIFICATION_TYPE_INFO__); } else { $this->notification->addNotification(_t("Your message could not be sent"), __NOTIFICATION_TYPE_INFO__); } $this->ViewOrder(); }