Example #1
0
 /**
  * Delete this Product from the database.
  *
  * Associated Attributes and pictures are deleted with it.
  * @return  boolean                         True on success, false otherwise
  * @global  ADONewConnection  $objDatabase  Database connection object
  * @author  Reto Kohli <*****@*****.**>
  */
 function delete($flagDeleteImages = false)
 {
     global $objDatabase;
     // TODO: MUST NOT delete while the Product is part of any Order!
     if (!$this->id) {
         return false;
     }
     if ($flagDeleteImages) {
         // Heck, most of this should go into the ProductPicture class...
         // Split picture data into single pictures
         $arrPictures = explode(':', $this->pictures);
         foreach ($arrPictures as $strPicture) {
             if (empty($strPicture)) {
                 continue;
             }
             // Split picture into name, width, height -- all are base64
             // encoded!
             $arrPicture = explode('?', $strPicture);
             $strFileName = base64_decode($arrPicture[0]);
             // If it is the default image, skip it
             if (preg_match('/' . ShopLibrary::noPictureName . '$/', $strFileName)) {
                 continue;
             }
             // Verify that no other Product uses the same picture.
             // $arrPicture[0] contains the encoded file name
             $query = "\n                    SELECT picture FROM " . DBPREFIX . "module_shop" . MODULE_INDEX . "_products\n                     WHERE picture LIKE '%" . addslashes($arrPicture[0]) . "%'";
             $objResult = $objDatabase->Execute($query);
             if ($objResult->RecordCount() == 1) {
                 // The only one -- it can be deleted.
                 // Delete the picture and thumbnail.
                 $thumbName = \Image::getThumbnailPath($strFileName);
                 // Continue even if deleting the images fails
                 \File::delete_file($strFileName);
                 \File::delete_file($thumbName);
             }
         }
     }
     // Remove any Text records present
     if (!\Text::deleteById($this->id, 'Shop', self::TEXT_NAME)) {
         return false;
     }
     if (!\Text::deleteById($this->id, 'Shop', self::TEXT_SHORT)) {
         return false;
     }
     if (!\Text::deleteById($this->id, 'Shop', self::TEXT_LONG)) {
         return false;
     }
     if (!\Text::deleteById($this->id, 'Shop', self::TEXT_KEYS)) {
         return false;
     }
     if (!\Text::deleteById($this->id, 'Shop', self::TEXT_CODE)) {
         return false;
     }
     if (!\Text::deleteById($this->id, 'Shop', self::TEXT_URI)) {
         return false;
     }
     // Delete the Product attribute relations and the Product itself
     // TEST
     if (!Attributes::removeFromProduct($this->id)) {
         return false;
     }
     \Env::get('cx')->getEvents()->triggerEvent('model/preRemove', array(new \Doctrine\ORM\Event\LifecycleEventArgs($this, \Env::get('em'))));
     $objResult = $objDatabase->Execute("\n            DELETE FROM " . DBPREFIX . "module_shop" . MODULE_INDEX . "_products\n                WHERE id={$this->id}");
     if (!$objResult) {
         return false;
     }
     \Env::get('cx')->getEvents()->triggerEvent('model/postRemove', array(new \Doctrine\ORM\Event\LifecycleEventArgs($this, \Env::get('em'))));
     $objDatabase->Execute("\n            OPTIMIZE TABLE " . DBPREFIX . "module_shop" . MODULE_INDEX . "_products");
     return true;
 }
Example #2
0
 /**
  * Uploads an image file and stores its information in the database
  * @param   string  $upload_field_name  File input field name
  * @param   string  $target_path        Target path, relative to the
  *                                      document root, including the
  *                                      file name
  * @return  integer                     The new image ID on success,
  *                                      false otherwise
  * @author    Reto Kohli <*****@*****.**>
  */
 static function uploadAndStore($upload_field_name, &$target_path, $image_id = false, $imagetype_key = false, $ord = false)
 {
     // $target_path *SHOULD* be like ASCMS_HOTELCARD_IMAGES_FOLDER.'/folder/name.ext'
     // Strip path offset, if any, from the target path
     $target_path = preg_replace('/^' . preg_quote(ASCMS_PATH_OFFSET, '/') . '/', '', $target_path);
     if (!File::upload_file_http($upload_field_name, $target_path, self::MAXIMUM_UPLOAD_FILE_SIZE, Filetype::MIMETYPE_IMAGES_WEB)) {
         //echo("Image::uploadAndStore($upload_field_name, $target_path, $image_id, $imagetype_key, $ord): Failed to upload<br />");
         return false;
     }
     if ($image_id && $ord === false) {
         $ord = self::getNextOrd($image_id, $imagetype_key);
     }
     $objImage = new Image($ord, $image_id);
     $objImage->setPath($target_path);
     $size = getimagesize(ASCMS_DOCUMENT_ROOT . '/' . $target_path);
     $objImage->setWidth($size[0]);
     $objImage->setHeight($size[1]);
     $objImage->setImageTypeKey($imagetype_key);
     //echo("Image::uploadAndStore(): Made Image:<br />".var_export($objImage, true)."<br />");
     if (!$objImage->store()) {
         //echo("Image::uploadAndStore(): Failed to store<br />");
         //            if (!
         File::delete_file($target_path);
         //            ) {
         //echo("Image::uploadAndStore(): Failed to delete file $target_path<br />");
         //            }
         return false;
     }
     //echo("Image::uploadAndStore(): Successfully stored<br />");
     if ($imagetype_key) {
         if (!$objImage->resize()) {
             File::delete_file($target_path);
             return false;
         }
     }
     return $objImage->id;
 }
Example #3
0
 /**
  * Update and store all settings found in the $_POST array
  *
  * Note that you *MUST* call {@see init()} beforehand, or your settings
  * will be unknown and thus not be stored.
  * Sets up an error message on failure.
  * @return  boolean                 True on success, null on noop,
  *                                  or false on failure
  */
 static function storeFromPost()
 {
     global $_CORELANG;
     //echo("self::storeFromPost(): POST:<br />".nl2br(htmlentities(var_export($_POST, true)))."<hr />");
     //echo("self::storeFromPost(): FILES:<br />".nl2br(htmlentities(var_export($_FILES, true)))."<hr />");
     // There may be several tabs for different groups being edited, so
     // load the full set of settings for the module.
     // Note that this is why setting names should be unique.
     // TODO: You *MUST* call this yourself *before* in order to
     // properly initialize the section!
     // self::init();
     $engine = self::getSectionEngine();
     if ($engine == null) {
         return false;
     }
     $arrSettings = $engine->getArraySetting();
     unset($_POST['bsubmit']);
     $result = true;
     // Compare POST with current settings and only store what was changed.
     foreach (array_keys($arrSettings) as $name) {
         if (isset($_POST[$name])) {
             $value = contrexx_input2raw($_POST[$name]);
             //if (preg_match('/^'.preg_quote(CSRF::key(), '/').'$/', $name))
             //continue;
             switch ($arrSettings[$name]['type']) {
                 case self::TYPE_FILEUPLOAD:
                     // An empty folder path has been posted, indicating that the
                     // current file should be removed
                     if (empty($value)) {
                         //echo("Empty value, deleting file...<br />");
                         if ($arrSettings[$name]['value']) {
                             if (\File::delete_file($arrSettings[$name]['value'])) {
                                 //echo("File deleted<br />");
                                 $value = '';
                             } else {
                                 //echo("Failed to delete file<br />");
                                 \Message::error(\File::getErrorString());
                                 $result = false;
                             }
                         }
                     } else {
                         // No file uploaded.  Skip.
                         if (empty($_FILES[$name]['name'])) {
                             continue;
                         }
                         // $value is the target folder path
                         $target_path = $value . '/' . $_FILES[$name]['name'];
                         // TODO: Test if this works in all browsers:
                         // The path input field name is the same as the
                         // file upload input field name!
                         $result_upload = \File::upload_file_http($name, $target_path, \Filetype::MAXIMUM_UPLOAD_FILE_SIZE, $arrSettings[$name]['values']);
                         // If no file has been uploaded at all, ignore the no-change
                         // TODO: Noop is not implemented in File::upload_file_http()
                         // if ($result_upload === '') continue;
                         if ($result_upload === true) {
                             $value = $target_path;
                         } else {
                             //echo("self::storeFromPost(): Error uploading file for setting $name to $target_path<br />");
                             // TODO: Add error message
                             \Message::error(\File::getErrorString());
                             $result = false;
                         }
                     }
                     break;
                 case self::TYPE_CHECKBOX:
                     break;
                 case self::TYPE_CHECKBOXGROUP:
                     $value = is_array($value) ? join(',', array_keys($value)) : $value;
                     // 20120508
                 // 20120508
                 case self::TYPE_RADIO:
                     break;
                 default:
                     // Regular value of any other type
                     break;
             }
             //\DBG::log('setting value ' . $name . ' = ' . $value);
             self::set($name, $value);
         }
     }
     //echo("self::storeFromPost(): So far, the result is ".($result ? 'okay' : 'no good')."<br />");
     $result_update = self::updateAll();
     if ($result_update === false) {
         \Message::error($_CORELANG['TXT_CORE_SETTING_ERROR_STORING']);
     } elseif ($result_update === true) {
         \Message::ok($_CORELANG['TXT_CORE_SETTING_STORED_SUCCESSFULLY']);
     }
     // If nothing bad happened above, return the result of updateAll(),
     // which may be true, false, or the empty string
     if ($result === true) {
         return $result_update;
     }
     // There has been an error anyway
     return false;
 }
Example #4
0
 function FileRemove()
 {
     $path = $_POST['path'];
     include_once ROOT . DS . 'includes' . DS . 'file.php';
     $file = new File();
     $path = dirname(ROOT) . DS . $path;
     $path = str_replace('/', DS, $path);
     $check = $file->delete_file($path);
     if ($check == true) {
         echo '1';
     } else {
         echo lang('media_remove_file_msg');
     }
     exit;
 }
Example #5
0
 /**
  * Сохранение поля "Файл"
  * @return void
  */
 public function save_variable_file()
 {
     if ($_POST['type'] == 1) {
         if (!empty($_FILES["attachment_img"]['name'])) {
             $extension_array = array('jpg', 'jpeg', 'gif', 'png');
             $new_name = strtolower($this->diafan->translit($_FILES["attachment_img"]['name']));
             $extension = substr(strrchr($new_name, '.'), 1);
             if (!in_array($extension, $extension_array)) {
                 throw new Exception('Не удалось загрузить файл. Возможно, закрыт доступ к папке или файл превышает максимально допустимый размер');
             }
             $new_name = substr($new_name, 0, -(strlen($extension) + 1)) . '_' . $this->diafan->id . '.' . $extension;
             $file_name = DB::query_result("SELECT file FROM {bs} WHERE id=%d LIMIT 1", $this->diafan->id);
             if (!empty($file_name)) {
                 File::delete_file(USERFILES . '/' . $this->diafan->table . '/' . $file_name);
             }
             File::upload_file($_FILES["attachment_img"]['tmp_name'], USERFILES . "/pbs/" . $new_name);
             $this->diafan->set_query("file='%s'");
             $this->diafan->set_value($new_name);
             $this->diafan->set_query("html='%s'");
             $this->diafan->set_value('');
             $this->diafan->set_query("width='%d'");
             $this->diafan->set_value('');
             $this->diafan->set_query("height='%d'");
             $this->diafan->set_value('');
         }
         $this->diafan->set_query("type=%d");
         $this->diafan->set_value(1);
         $this->diafan->set_query("alt" . _LANG . "='%s'");
         $this->diafan->set_value($_POST['alt']);
         $this->diafan->set_query("title" . _LANG . "='%s'");
         $this->diafan->set_value($_POST['title']);
     }
     if ($_POST['type'] == 2) {
         if (!empty($_FILES["attachment_swf"]['name'])) {
             $extension_array = array('swf');
             $new_name = strtolower($this->diafan->translit($_FILES["attachment_swf"]['name']));
             $extension = substr(strrchr($new_name, '.'), 1);
             if (!in_array($extension, $extension_array)) {
                 throw new Exception($this->diafan->_('Не удалось загрузить файл. Возможно, закрыт доступ к папке или файл превышает максимально допустимый размер'));
             }
             $new_name = substr($new_name, 0, -(strlen($extension) + 1)) . '_' . $this->diafan->id . '.' . $extension;
             $file_name = DB::query_result("SELECT file FROM {bs} WHERE id=%d LIMIT 1", $this->diafan->id);
             if (!empty($file_name)) {
                 File::delete_file(USERFILES . '/' . $this->diafan->table . '/' . $file_name);
             }
             File::upload_file($_FILES["attachment_swf"]['tmp_name'], USERFILES . "/" . $this->diafan->table . '/' . $new_name);
             $this->diafan->set_query("file='%s'");
             $this->diafan->set_value($new_name);
             $this->diafan->set_query("html='%s'");
             $this->diafan->set_value('');
             $this->diafan->set_query("alt" . _LANG . "='%s'");
             $this->diafan->set_value('');
             $this->diafan->set_query("title" . _LANG . "='%s'");
             $this->diafan->set_value('');
         }
         $this->diafan->set_query("type='%d'");
         $this->diafan->set_value(2);
         $this->diafan->set_query("width='%d'");
         $this->diafan->set_value($_POST['width']);
         $this->diafan->set_query("height='%d'");
         $this->diafan->set_value($_POST['height']);
     }
     if ($_POST['type'] == 3) {
         if (!empty($_POST['html'])) {
             $file_name = DB::query_result("SELECT file FROM {bs} WHERE id=%d LIMIT 1", $this->diafan->id);
             if (!empty($file_name)) {
                 File::delete_file(USERFILES . '/' . $this->diafan->table . '/' . $file_name);
             }
             $this->diafan->set_query("html='%s'");
             $this->diafan->set_value($_POST['html']);
             $this->diafan->set_query("file='%s'");
             $this->diafan->set_value('');
             $this->diafan->set_query("alt" . _LANG . "='%s'");
             $this->diafan->set_value('');
             $this->diafan->set_query("title" . _LANG . "='%s'");
             $this->diafan->set_value('');
             $this->diafan->set_query("width='%d'");
             $this->diafan->set_value('');
             $this->diafan->set_query("height='%d'");
             $this->diafan->set_value('');
         }
         $this->diafan->set_query("type='%d'");
         $this->diafan->set_value(3);
     }
 }
Example #6
0
 /**
  * Deletes this ShopCategory from the database.
  *
  * Also removes associated subcategories and Products.
  * Images will only be erased from the disc if the optional
  * $flagDeleteImages parameter evaluates to true.
  * @return  boolean                 True on success, false otherwise
  * @global  ADONewConnection  $objDatabase    Database connection object
  * @author  Reto Kohli <*****@*****.**>
  */
 function delete($flagDeleteImages = false)
 {
     global $objDatabase;
     // Delete Products and images
     if (Products::deleteByShopCategory($this->id, $flagDeleteImages) === false) {
         return false;
     }
     // Delete subcategories
     foreach ($this->getChildCategories() as $subCategory) {
         if (!$subCategory->delete($flagDeleteImages)) {
             return false;
         }
     }
     // TEST: Delete pictures, if requested
     if ($flagDeleteImages) {
         \File::delete_file($this->picture());
     }
     // Delete Text
     \Text::deleteById($this->id(), 'Shop', self::TEXT_NAME);
     \Text::deleteById($this->id(), 'Shop', self::TEXT_DESCRIPTION);
     // Delete Category
     $objResult = $objDatabase->Execute("\n            DELETE FROM " . DBPREFIX . "module_shop" . MODULE_INDEX . "_categories\n            WHERE id={$this->id}");
     if (!$objResult) {
         return false;
     }
     $objDatabase->Execute("\n            OPTIMIZE TABLE " . DBPREFIX . "module_shop" . MODULE_INDEX . "_categories");
     return true;
 }
Example #7
0
 /**
  * Deletes the Order with the given ID
  * @param   integer   $order_id     The Order ID
  * @return  boolean                 True on success, false otherwise
  */
 static function deleteById($order_id)
 {
     global $objDatabase, $_ARRAYLANG;
     $order_id = intval($order_id);
     if (empty($order_id)) {
         return false;
     }
     $arrItemId = self::getItemIdArray($order_id);
     if (!empty($arrItemId)) {
         foreach ($arrItemId as $item_id) {
             // Delete files uploaded with the order
             $query = "\n                    SELECT `option_name`\n                      FROM `" . DBPREFIX . "module_shop" . MODULE_INDEX . "_order_attributes`\n                     WHERE `item_id`={$item_id}";
             $objResult = $objDatabase->Execute($query);
             if (!$objResult) {
                 return self::errorHandler();
             }
             while (!$objResult->EOF) {
                 $path = Order::UPLOAD_FOLDER . $objResult->fields['option_name'];
                 if (\File::exists($path)) {
                     if (!\File::delete_file($path)) {
                         \Message::error(sprintf($_ARRAYLANG['TXT_SHOP_ERROR_DELETING_FILE'], $path));
                     }
                 }
                 $objResult->MoveNext();
             }
             $query = "\n                    DELETE FROM `" . DBPREFIX . "module_shop" . MODULE_INDEX . "_order_attributes`\n                     WHERE `item_id`={$item_id}";
             if (!$objDatabase->Execute($query)) {
                 return \Message::error($_ARRAYLANG['TXT_SHOP_ERROR_DELETING_ORDER_ATTRIBUTES']);
             }
         }
     }
     $query = "\n            DELETE FROM `" . DBPREFIX . "module_shop" . MODULE_INDEX . "_order_items`\n             WHERE `order_id`={$order_id}";
     if (!$objDatabase->Execute($query)) {
         return \Message::error($_ARRAYLANG['TXT_SHOP_ERROR_DELETING_ORDER_ITEMS']);
     }
     $query = "\n            DELETE FROM `" . DBPREFIX . "module_shop" . MODULE_INDEX . "_lsv`\n             WHERE `order_id`={$order_id}";
     if (!$objDatabase->Execute($query)) {
         return \Message::error($_ARRAYLANG['TXT_SHOP_ERROR_DELETING_ORDER_LSV']);
     }
     // Remove accounts autocreated for downloads
     // TODO: TEST!
     $objOrder = self::getById($order_id);
     if ($objOrder) {
         $customer_id = $objOrder->customer_id();
         $objCustomer = Customer::getById($customer_id);
         if ($objCustomer) {
             $customer_email = Orders::usernamePrefix . "_{$order_id}_%-" . $objCustomer->email();
             $objUser = \FWUser::getFWUserObject()->objUser->getUsers(array('email' => $customer_email));
             if ($objUser) {
                 while (!$objUser->EOF) {
                     if (!$objUser->delete()) {
                         return false;
                     }
                     $objUser->next();
                 }
             }
         }
     }
     $query = "\n            DELETE FROM `" . DBPREFIX . "module_shop" . MODULE_INDEX . "_orders`\n             WHERE `id`={$order_id}";
     if (!$objDatabase->Execute($query)) {
         return \Message::error($_ARRAYLANG['TXT_SHOP_ERROR_DELETING_ORDER']);
     }
     return true;
 }