/** * editAction * Get a record and populate the application form * @return unknown_type */ public function editAction() { $form = $this->getForm('/admin/ordersitems/process'); $id = $this->getRequest()->getParam('id'); // Create the buttons in the edit form $this->view->buttons = array(array("url" => "#", "label" => $this->translator->translate('Save'), "params" => array('css' => null, 'id' => 'submit')), array("url" => "/admin/ordersitems/list", "label" => $this->translator->translate('List'), "params" => array('css' => null, 'id' => 'submit')), array("url" => "/admin/ordersitems/new/", "label" => $this->translator->translate('New'), "params" => array('css' => null))); if (!empty($id) && is_numeric($id)) { $rs = OrdersItems::getAllInfo($id); if (!empty($rs)) { // Load the domains attached to the order $form->getElement('domains_selected')->setMultiOptions(OrdersItemsDomains::getList($id)); $rs['date_start'] = Shineisp_Commons_Utilities::formatDateOut($rs['date_start']); $rs['date_end'] = !empty($rs['date_end']) ? Shineisp_Commons_Utilities::formatDateOut($rs['date_end']) : ""; $form->populate($rs); // send the order id in the view $this->view->order_id = $rs['order_id']; // send the customer id in the view $this->view->customer_id = $rs['Orders']['customer_id']; // Check if the product is a hosting plan $this->view->isHosting = !empty($rs['Products']['type']) && $rs['Products']['type'] == "hosting" ? true : false; // Create the buttons in the edit form $this->view->buttons[] = array("url" => "/admin/ordersitems/confirm/id/{$id}", "label" => $this->translator->translate('Delete'), "params" => array('css' => null)); $this->view->buttons[] = array("url" => "/admin/services/edit/id/{$id}", "label" => $this->translator->translate('Service'), "params" => array('css' => null)); $this->view->buttons[] = array("url" => "/admin/orders/edit/id/" . $rs['order_id'], "label" => $this->translator->translate('Order'), "params" => array('css' => null)); $this->view->buttons[] = array("url" => "/admin/customers/edit/id/" . $rs['Orders']['customer_id'], "label" => $this->translator->translate('Customers'), "params" => array('css' => null)); } else { $this->_helper->redirector('list', 'orders', 'admin', array('mex' => $this->translator->translate('Unable to find the order item selected.'), 'status' => 'danger')); } } else { $this->_helper->redirector('list', 'orders', 'admin', array('mex' => $this->translator->translate('Unable to find the order item selected.'), 'status' => 'danger')); } $this->view->title = $this->translator->translate("Service edit"); $this->view->description = $this->translator->translate("Here you can edit the service selected"); $this->view->form = $form; $this->render('applicantform'); }
/** * Get the setup configuration * * * @return ArrayObject */ public static function getSetup($id) { $setup = ""; $services = array(); $panel = Isp::getPanel(); $records = Doctrine_Query::create()->from('OrdersItems oi')->leftJoin('oi.Products p')->where('oi.detail_id = ?', $id)->execute(array(), Doctrine_Core::HYDRATE_ARRAY); foreach ($records as $record) { if (!empty($record['Products']['setup'])) { $setup = $record['Products']['setup']; // Get the parameters set in the order details (service) $params = json_decode($record['parameters'], true); if (is_array($params)) { // Get the list of all the domains $domains = OrdersItemsDomains::get_domains($record['detail_id']); // We have to get the first domain if (!empty($domains[0]['domain'])) { $params['domain'] = $domains[0]['domain']; // Get all the var {string} in the xml setup preg_match_all('/{([^}]+)}/Ui', $setup, $matches); foreach ($matches[1] as $parameter) { $setup = str_replace("{" . $parameter . "}", $params[$parameter], $setup); } } } } } $xml = simplexml_load_string($setup); $arrSetup = Shineisp_Commons_Utilities::simpleXMLToArray($xml); return $arrSetup; }
/** * Add an item within an order * * @param Cart $item * @throws Exception * @return unknown */ public static function addOrderItem(CartItem $item) { if (empty(self::$order)) { throw new Exception('The order has not been created yet', 1000); } try { // get the item subtotals $subtotals = $item->getSubtotals(); // get the options $options = $item->getOptions(); // Get the order object previously created $order = self::$order; // add a new item $orderitem = new OrdersItems(); $orderitem->order_id = $order['order_id']; if ("domain" == $item->getType()) { // Create a new domain order item $orderitem->tld_id = !empty($options['domain']['tld']) ? $options['domain']['tld'] : null; $orderitem->parameters = json_encode($options); } else { $orderitem->product_id = $item->getId(); $orderitem->parameters = json_encode(ProductsAttributes::getSystemAttributes($item->getId())); } $orderitem->status_id = Statuses::id("tobepaid", "orders"); $orderitem->date_start = date('Y-m-d H:i:s'); $orderitem->date_end = null; $orderitem->description = $item->getName(); $orderitem->quantity = $item->getQty(); $orderitem->price = $item->getUnitprice(); $orderitem->billing_cycle_id = $item->getBillingid(); $orderitem->vat = $subtotals['taxes']; $orderitem->percentage = $subtotals['percentage']; $orderitem->uuid = $item->getUid(); // Count of the day until the expiring if ($item->getIsrecurring()) { // get the months until of the next service expiration $months = $subtotals['months']; if ($months > 0) { $totmonths = intval($item->getQty() * $months); // Calculate the total of the months $date_end = Shineisp_Commons_Utilities::add_date(date('d-m-Y H:i:s'), null, $totmonths); $orderitem->date_end = Shineisp_Commons_Utilities::formatDateIn($date_end); } else { $orderitem->date_end = null; } } $orderitem->cost = $item->getCost(); $orderitem->setupfee = $subtotals['setupfee']; $orderitem->subtotal = $subtotals['subtotal']; // Save the order item if ($orderitem->trySave()) { // Attach all the the domain to the order if ("domain" == $item->getType()) { $domain = $options['domain']['name']; $tld = $options['domain']['tld']; $domainId = Domains::Create($domain, $tld, $order->customer_id, $orderitem->detail_id); if (is_numeric($domainId)) { $ordersitemsdomains = new OrdersItemsDomains(); $ordersitemsdomains->domain_id = $domainId; $ordersitemsdomains->order_id = $order['order_id']; $ordersitemsdomains->orderitem_id = $orderitem->detail_id; $ordersitemsdomains->save(); } } // Update the totals of the order self::updateTotalsOrder($order['order_id']); return $orderitem; } } catch (Exception $e) { Shineisp_Commons_Utilities::log('There was a problem during the order creation: ' . $e->getMessage()); } return false; }
/** * Attach a hosting service to a domain name * * * @param integer $orderID * @param integer $domainID */ public static function addDomain($orderID, $domainID) { if (is_numeric($orderID) && is_numeric($domainID)) { $order = Orders::find($orderID); if (!empty($order)) { foreach ($order->OrdersItems as $detail) { // if ($detail->Products['type'] == "hosting") { #if(FALSE === self::check_domains_in_order($orderID, $domainID)){ $domain = new OrdersItemsDomains(); $domain['domain_id'] = $domainID; $domain['order_id'] = $orderID; $domain['orderitem_id'] = $detail['detail_id']; $domain->save(); #} // } } return true; } } return false; }
/** * Get all the domains not included in a order items * * * @param $detail_id * @return array */ public static function getFreeOrderDomainsList($detail_id) { $items = array(); try { $DomainsInOrders = OrdersItemsDomains::getList($detail_id); if (count($DomainsInOrders) > 0) { $DomainsInOrders = array_keys($DomainsInOrders); } $dq = Doctrine_Query::create()->select('d.domain_id, d.domain as domain, ws.tld as tld')->from('Domains d')->leftJoin('d.DomainsTlds dt')->leftJoin('dt.WhoisServers ws')->leftJoin('d.OrdersItemsDomains oid ')->leftJoin('d.Customers c')->whereIn('d.domain_id', $DomainsInOrders, true)->addWhere("c.isp_id = ?", Isp::getCurrentId())->orderBy('ws.tld, d.domain'); $domains = $dq->execute(array(), Doctrine_Core::HYDRATE_ARRAY); foreach ($domains as $domain) { $items[$domain['domain_id']] = $domain['domain'] . "." . $domain['tld']; } } catch (Exception $e) { die($e->getMessage()); } return $items; }
/** * editAction * Get a record and populate the application form * @return unknown_type */ public function editAction() { $form = $this->getForm('/admin/services/process'); $service_domains = new OrdersItemsDomains(); $id = $this->getRequest()->getParam('id'); // Create the buttons in the edit form $this->view->buttons = array(array("url" => "#", "label" => $this->translator->translate('Save'), "params" => array('css' => null, 'id' => 'submit')), array("url" => "/admin/services/list", "label" => $this->translator->translate('List'), "params" => array('css' => null, 'id' => 'submit')), array("url" => "/admin/services/new/", "label" => $this->translator->translate('New'), "params" => array('css' => null))); try { if (!empty($id) && is_numeric($id)) { $form->getElement('domains')->setMultiOptions(Domains::getFreeOrderDomainsList($id)); $rs = $this->services->getAllInfo($id, null, true); if (!empty($rs)) { $form->getElement('domains_selected')->setMultiOptions($service_domains->getList($id)); $rs['date_start'] = Shineisp_Commons_Utilities::formatDateOut($rs['date_start']); $rs['date_end'] = Shineisp_Commons_Utilities::formatDateOut($rs['date_end']); $rs['customer_id'] = $rs['Orders']['customer_id']; $form->populate($rs); $this->view->buttons[] = array("url" => "/admin/services/confirm/id/{$id}", "label" => $this->translator->translate('Delete'), "params" => array('css' => null)); $this->view->buttons[] = array("url" => "/admin/orders/edit/id/" . $rs['Orders']['order_id'], "label" => $this->translator->translate('Order'), "params" => array('css' => null)); } // Get all the messages attached to the ordersitems $this->view->messages = Messages::getbyServiceId($id); $this->view->owner_datagrid = $this->ownerGrid($rs['Orders']['customer_id']); } } catch (Exception $e) { echo $e->getMessage(); } $this->view->title = $this->translator->translate("Service Details"); $this->view->description = $this->translator->translate("Here you can see the details of the service subscribed by the customer."); $this->view->mex = $this->getRequest()->getParam('mex'); $this->view->mexstatus = $this->getRequest()->getParam('status'); $this->view->form = $form; $this->render('applicantform'); }
/** * Create a new website * * Executes the creation of new website in the IspConfig control panel * Note in order to not fail this command, it must meet the following requirements: * * - The customer must be registered in the db. * - The parameters must be saved in the service detail (orderitems table) * * @param array $task Must be a valid task * @return mixed True, or throw an Exception if failed. * @access public */ public function create_website(array $task) { $params = array(); try { $server = self::getServer($task['orderitem_id'], 'web'); // Get the server id if (!empty($server['server_id']) && is_numeric($server['server_id'])) { $clientId = self::get_client_id($task, $server['server_id']); // Connection to the SOAP system $client = $this->connect($server['server_id']); // Get the remote server ID set in the servers profile in ShineISP $customAttribute = CustomAttributes::getAttribute($server['server_id'], "remote_server_id"); // Get the remote server id set in ShineISP if (is_numeric($customAttribute['value'])) { $ServerId = $customAttribute['value']; // Get the Json encoded parameters in the task $parameters = json_decode($task['parameters'], true); // Get the domain $domains = OrdersItemsDomains::get_domains($task['orderitem_id']); if (!empty($domains[0]['domain'])) { $params = array('server_id' => $ServerId, 'ip_address' => '*', 'domain' => $domains[0]['domain'], 'type' => 'vhost', 'parent_domain_id' => 0, 'vhost_type' => 'name', 'hd_quota' => $parameters['webspace'], 'traffic_quota' => $parameters['trafficdata'], 'cgi' => 'n', 'ssi' => 'n', 'suexec' => 'y', 'errordocs' => 1, 'is_subdomainwww' => 1, 'subdomain' => 'www', 'php' => 'fast-cgi', 'ruby' => 'n', 'redirect_type' => '', 'redirect_path' => '', 'ssl' => 'n', 'ssl_state' => '', 'ssl_locality' => '', 'ssl_organisation' => '', 'ssl_organisation_unit' => '', 'ssl_country' => '', 'ssl_domain' => '', 'ssl_request' => '', 'ssl_cert' => '', 'ssl_bundle' => '', 'ssl_action' => '', 'stats_password' => '', 'stats_type' => 'webalizer', 'allow_override' => 'All', 'apache_directives' => '', 'php_open_basedir' => '/', 'custom_php_ini' => '', 'backup_interval' => '', 'backup_copies' => 1, 'active' => 'y', 'traffic_quota_lock' => 'n', 'pm_process_idle_timeout' => '10', 'pm_max_requests' => '0'); try { $websiteId = $client->sites_web_domain_add($this->getSession(), $clientId, $params, $readonly = false); if (!is_numeric($websiteId)) { throw new Exception("There was a problem with website creation: sites_web_domain_add doesn't return the websiteID identifier", "3505"); } } catch (SoapFault $e) { throw new Exception("There was a problem with " . $domains[0]['domain'] . " website creation: " . $e->getMessage() . " - Parameters: " . json_encode($params), "3504"); } // Add relation between order_item and server OrdersItemsServers::addServer($task['orderitem_id'], $server['server_id']); // Create the log message Shineisp_Commons_Utilities::logs("ID: " . $task['action_id'] . " - " . __METHOD__ . " - Parameters: " . json_encode($params), "ispconfig.log"); } else { throw new Exception("No domain set for the selected service in the ShineISP service order detail ID #: " . $task['orderitem_id'], "3503"); } } else { throw new Exception("No remote web server id set in the ShineISP server profile.", "3502"); } } else { throw new Exception("Web Server has not been found in IspConfig server settings.", "3501"); } // Logout from the IspConfig Remote System $client->logout($this->getSession()); return $websiteId; } catch (Exception $e) { Shineisp_Commons_Utilities::logs(__METHOD__ . ": " . $e->getMessage()); } }