/** * Save the file information in the database * @param string $filepath * @param string $attachedto * @param integer $id * @param integer $categoryID (default 3 - Documents) */ public static function saveit($filename, $path, $attachedto, $id, $categoryID = 3) { $file = new Files(); $file->file = $filename; $file->path = $path; $file->attachedto = $attachedto; $file->publickey = Shineisp_Commons_Uuid::generate(); $file->id = $id; $file->date = date('Y-m-d H:i:s'); $file->ip = $_SERVER['REMOTE_ADDR']; $file->category_id = $categoryID; if ($file->trySave()) { return $path . $filename; } return false; }
public function simplegrid($data) { $this->view->module = Zend_Controller_Front::getInstance()->getRequest()->getModuleName(); $this->view->controller = Zend_Controller_Front::getInstance()->getRequest()->getControllerName(); $this->view->action = Zend_Controller_Front::getInstance()->getRequest()->getActionName(); if (isset($data['records'])) { // Name of the table, useful for the jQuery pager $this->view->name = !empty($data['name']) ? $data['name'] : "table_" . Shineisp_Commons_Uuid::generate(); // Index of the table $this->view->id = !empty($this->view->fields[0]) && is_numeric($data['records'][0][$this->view->fields[0]]) ? $data['records'][0][$this->view->fields[0]] : "0"; // All the records $this->view->records = $data['records']; // Create the header using the field name if the columns variable is not set if (empty($data['columns'])) { $data['columns'] = array(); if (!empty($data['records'][0])) { // Get all the fields $items = Shineisp_Commons_Utilities::array_flatten($data['records'][0]); $fields = array_keys($items); foreach ($fields as $field) { if (strpos($field, "_id") === false) { // When a record is called using the HYDRATE_SCALAR mode the table aliases are attached in the field name // In this way we delete the first part of the field name. For instance: o_name --> name $arrfield = explode("_", $field); $field = count($arrfield) > 0 ? $arrfield[count($arrfield) - 1] : $field; $data['columns'][] = ucfirst(Shineisp_Registry::getInstance()->Zend_Translate->translate($field)); } } } } $this->view->columns = $data['columns']; // If these options are true a link appear for each row in a table $this->view->view = !empty($data['view']) ? $data['view'] : false; $this->view->edit = !empty($data['edit']) ? $data['edit'] : false; $this->view->delete = !empty($data['delete']) ? $data['delete'] : false; $this->view->targetlink = !empty($data['targetlink']) ? $data['targetlink'] : null; // If you need more action use this parameter Array{'url'=>'name'} // for instance $actions['/admin/customers'] = "Customers"; // the label customers will be translated $this->view->actions = !empty($data['actions']) ? $data['actions'] : false; $this->view->onclick = !empty($data['onclick']) ? $data['onclick'] : false; } else { $this->view->records = ""; } // Path of the template return $this->view->render('partials/simplegrid.phtml'); }
public function __construct() { $this->id = null; $this->uid = Shineisp_Commons_Uuid::generate(); $this->term = null; $this->qty = 1; $this->name = null; $this->unitprice = null; $this->subtotals = null; $this->type = null; $this->isrecurring = false; $this->options = null; }
/** * Save all the data * * * @param unknown_type $data * @param unknown_type $locale */ public static function saveAll($id, $params, $locale = 1) { $products = new Products(); // Set the new values if (is_numeric($id)) { $products = self::find($id, null, false, $locale); if ($products[0]) { $products = $products[0]; } } else { $products->inserted_at = date('Y-m-d H:i:s'); } // Product UUID is missing, generate a new one if (empty($products->uuid)) { $products->uuid = Shineisp_Commons_Uuid::generate(); } try { if (!empty($_FILES['attachments'])) { $file = $_FILES['attachments']; if (!empty($file)) { if (!is_dir(PUBLIC_PATH . "/media/products/")) { @mkdir(PUBLIC_PATH . "/media"); @mkdir(PUBLIC_PATH . "/media/products"); } } } if (is_array($params)) { $products->updated_at = date('Y-m-d H:i:s'); $products->categories = !empty($params['categories']) ? $params['categories'] : null; $products->uri = !empty($params['uri']) ? Shineisp_Commons_UrlRewrites::format($params['uri']) : Shineisp_Commons_UrlRewrites::format($params['name']); $products->sku = !empty($params['sku']) ? $params['sku'] : ''; $products->cost = $params['cost']; $products->price_1 = !empty($params['price_1']) ? $params['price_1'] : NULL; $products->setupfee = !empty($params['setupfee']) ? $params['setupfee'] : NULL; $products->enabled = !empty($params['enabled']) ? 1 : 0; $products->iscomparable = !empty($params['iscomparable']) ? 1 : 0; $products->tax_id = !empty($params['tax_id']) ? $params['tax_id'] : NULL; $products->type = !empty($params['type']) ? $params['type'] : "generic"; $products->blocks = !empty($params['blocks']) ? $params['blocks'] : NULL; $products->group_id = !empty($params['group_id']) ? $params['group_id'] : NULL; $products->position = !empty($params['position']) ? $params['position'] : NULL; $products->setup = !empty($params['setup']) ? $params['setup'] : NULL; $products->ishighlighted = !empty($params['ishighlighted']) ? 1 : 0; $products->isrefundable = !empty($params['isrefundable']) ? 1 : 0; $products->showonrss = !empty($params['showonrss']) ? 1 : 0; $products->external_id = !empty($params['external_id']) ? $params['external_id'] : NULL; $products->downgradable = !empty($params['downgradable']) ? 1 : 0; $products->server_group_id = !empty($params['server_group_id']) ? intval($params['server_group_id']) : null; $products->autosetup = !empty($params['autosetup']) ? intval($params['autosetup']) : 0; $products->isp_id = Shineisp_Registry::get('ISP')->isp_id; // If 0 or NULL, se to NULL. Avoid constraint errors $products->welcome_mail_id = !empty($params['welcome_mail_id']) && intval($params['welcome_mail_id']) > 0 ? intval($params['welcome_mail_id']) : null; // Save the data $products->save(); $product_id = $products->product_id; // Save the product attributes ProductsAttributesIndexes::saveAll($params, $product_id); $Pdata = ProductsData::findbyProductID($product_id, $locale); if (empty($Pdata)) { $Pdata = new ProductsData(); } // TODO: Guestisp: this criteria is not complete. I cannot translate a product already sold in another language // a solution is write the name of the product sold in the order as flat data //* Product name can not be changed if product is sold // if ( ! (bool)OrdersItems::CheckIfProductExist($product_id) ) { // $Pdata->name = $params ['name']; // } $Pdata->name = $params['name']; $Pdata->nickname = $params['nickname']; $Pdata->shortdescription = $params['shortdescription']; $Pdata->description = $params['description']; $Pdata->metakeywords = $params['metakeywords']; $Pdata->metadescription = $params['metadescription']; $Pdata->product_id = $product_id; $Pdata->language_id = $locale; $Pdata->save(); // Create the price tranches if (!empty($params['tranche_qty']) && !empty($params['tranche_measure']) && !empty($params['tranche_price'])) { $params['tranche_setupfee'] = isset($params['tranche_setupfee']) ? $params['tranche_setupfee'] : 0; $tranches = ProductsTranches::saveAll($product_id, $params['tranche_billing_cycle_id'], $params['tranche_qty'], $params['tranche_measure'], $params['tranche_price'], $params['tranche_setupfee']); $trancheid = $tranches['tranche_id']; if (!empty($params['tranche_includes_domains'])) { foreach ($params['tranche_includes_domains'] as $includeid) { ProductsTranchesIncludes::saveAll($trancheid, $includeid, 'domains'); } } } // Attach the wiki pages to a product if (!empty($params['wikipages'])) { Wikilinks::addWikiPages2Products($product_id, $params['wikipages']); } // Add the related products if (!empty($params['related'])) { self::AddRelatedProducts($product_id, $params['related']); } // Add the upgrade products if (!empty($params['upgrade'])) { self::AddUpgradeProducts($product_id, $params['upgrade']); } // Before to get the Values of the form I upload the files in the folders if (!empty($file)) { if ($_FILES['attachments']['error'] == 0) { // Uploading the file $filename = mt_rand(10, 999) . '_' . $_FILES['attachments']['name']; $retval = move_uploaded_file($_FILES['attachments']['tmp_name'], PUBLIC_PATH . "/media/products/" . $filename); if ($retval) { $media = new ProductsMedia(); $media->filename = $filename; $media->path = "/media/products/{$filename}"; $media->product_id = $product_id; $media->description = $params['filedescription']; $media->enabled = 1; $media->save(); } } } return $product_id; } else { throw new Exception('Parameters data are not correct.'); } } catch (Exception $e) { echo $e->getMessage(); die; return false; } }
/** * Create and Retrieve the OrderID * @param integer $id * @return Orders */ public static function create($customerId, $statusId = "", $note = "") { $customer = Customers::getAllInfo($customerId); $isp_id = $customer['isp_id']; if (self::$order) { return self::$order; } if (is_numeric($customerId)) { $order = new Orders(); // Execute a custom event self::events()->trigger('orders_create_before', "Orders", array('order' => $order, 'customerid' => $customerId)); $order['customer_id'] = $customerId; $order['order_date'] = date('Y-m-d H:i:s'); $order['expiring_date'] = date('Y-m-d', strtotime('30 days', strtotime($order['order_date']))); $order['isp_id'] = $isp_id; $order['status_id'] = is_numeric($statusId) ? $statusId : Statuses::id("tobepaid", "orders"); $order['uuid'] = Shineisp_Commons_Uuid::generate(); // Save the data $order->save(); // Save order number $order->order_number = self::formatOrderId($order->order_id); // Save the order if ($order->trySave()) { // Log status change self::logStatusChange($order->order_id, $order->status_id); // Assign the order var to the static var self::$order = $order; // Create the fastlink for the order $fastlink = Fastlinks::CreateFastlink('orders', 'edit', json_encode(array('id' => $order['order_id'])), 'orders', $order['order_id'], $customerId); // Add a message within the order Messages::addMessage($note, $customerId, null, $order['order_id']); // Execute a custom event self::events()->trigger('orders_create_after', "Orders", array('order' => $order, 'fastlink' => $fastlink)); // Return the order object var return self::$order; } else { throw new Exception('There was a problem when I try to create the order', 1003); } } else { throw new Exception('Customer ID has been not found', 1001); } return null; }
/** * Create a new customer * * List of all the array parameters * * @param array_item firstname * @param array_item lastname * @param array_item email * @param array_item password * @param array_item company * @param array_item statusId * @param array_item gender * @param array_item birthplace * @param array_item birthdate * @param array_item birthcountry * @param array_item birthnationality * @param array_item vat * @param array_item taxpayernumber * @param array_item contact * @param array_item contacttype * @param array_item address * @param array_item city * @param array_item code * @param array_item country * @param array_item area * @param array_item legalform * @param array_item company_type_id * @param array_item welcome_mail * @param array_item parent_id * @param array_item isreseller */ public static function Create($data) { $locale = Shineisp_Registry::getInstance()->Zend_Locale; $customer = new Customers(); $isDisabled = false; $language_id = Languages::get_language_id_by_code((string) $locale); // By default, welcome mail is sent $data['welcome_mail'] = isset($data['welcome_mail']) ? intval($data['welcome_mail']) : true; // Customer's parameters. $customer->company = !empty($data['company']) ? $data['company'] : null; $customer->firstname = !empty($data['firstname']) ? $data['firstname'] : null; $customer->lastname = !empty($data['lastname']) ? $data['lastname'] : null; $customer->gender = !empty($data['gender']) ? $data['gender'] : null; $customer->email = $data['email'] ? $data['email'] : null; $customer->password = crypt($data['password']); $customer->birthplace = !empty($data['birthplace']) ? $data['birthplace'] : null; $customer->birthdate = !empty($data['birthdate']) ? Shineisp_Commons_Utilities::formatDateIn($data['birthdate']) : null; $customer->birthdistrict = !empty($data['birthdistrict']) ? $data['birthdistrict'] : null; $customer->birthcountry = !empty($data['birthcountry']) ? $data['birthcountry'] : null; $customer->birthnationality = !empty($data['birthnationality']) ? $data['birthnationality'] : null; $customer->note = !empty($data['note']) ? $data['note'] : Null; $customer->vat = !empty($data['vat']) ? $data['vat'] : Null; $customer->taxpayernumber = !empty($data['taxpayernumber']) ? $data['taxpayernumber'] : Null; // Let's try to get status_id from status if (isset($data['status']) && !empty($data['status'])) { $customer->status_id = Statuses::id($data['status'], 'Customers'); $isDisabled = isset($data['status']) && strtolower($data['status']) == 'disabled' ? true : false; } else { $customer->status_id = !empty($data['status_id']) ? $data['status_id'] : Statuses::id('Active', 'Customers'); } $customer->legalform_id = !empty($data['legalform']) ? $data['legalform'] : Null; $customer->type_id = !empty($data['company_type_id']) ? $data['company_type_id'] : Null; $customer->parent_id = !empty($data['parent_id']) ? $data['parent_id'] : Null; $customer->isreseller = !empty($data['isreseller']) ? $data['isreseller'] : Null; $customer->language_id = !empty($language_id) ? intval($language_id) : 1; $customer->created_at = date('Y-m-d H:i:s'); $customer->updated_at = date('Y-m-d H:i:s'); // Try to get the real isp_id, based on logged user or on request uri // TODO: this should be done better $customer->isp_id = Isp::getCurrentId(); // Generate an UUID. Used for API when you need to sync customers between services // TODO: allow custom uuid coming from api ? If yes, we should check for uniqueness in database $customer->uuid = Shineisp_Commons_Uuid::generate(); // customer disabled? Disable its password if ($isDisabled) { $customer->password = '******' . $customer->password; } // Save the data $customer->save(); if (!empty($data['contact'])) { $customer->Contacts[0]->contact = !empty($data['contact']) ? $data['contact'] : Null; $customer->Contacts[0]->type_id = !empty($data['contacttypes']) ? $data['contacttypes'] : Null; $customer->Contacts[0]->base = 1; $customer->save(); } if (!empty($data['address'])) { $customer->Addresses[0]->address = !empty($data['address']) ? $data['address'] : Null; $customer->Addresses[0]->city = !empty($data['city']) ? $data['city'] : Null; $customer->Addresses[0]->code = !empty($data['code']) ? $data['code'] : Null; $customer->Addresses[0]->country_id = !empty($data['country_id']) ? $data['country_id'] : Null; $customer->Addresses[0]->area = !empty($data['area']) ? $data['area'] : Null; $customer->save(); } $customerID = $customer->getIncremented(); // Add the customer email in the newsletter list if (!$isDisabled) { NewslettersSubscribers::customer_optIn($customer['customer_id']); } // Send the welcome email if ($data['welcome_mail'] == true && !$isDisabled) { self::welcome_mail($customerID, $data['password']); } return $customerID; }