public static function fileUpload() { global $lC_Database, $lC_Vqmod, $_module; $lC_Image = new lC_Image_Admin(); if (is_numeric($_GET[$_module])) { require_once $lC_Vqmod->modCheck('includes/classes/ajax_upload.php'); // list of valid extensions, ex. array("jpeg", "xml", "bmp") $allowedExtensions = array('gif', 'jpg', 'jpeg', 'png'); // max file size in bytes $sizeLimit = 10 * 1024 * 1024; $uploader = new qqFileUploader($allowedExtensions, $sizeLimit); $products_image = $uploader->handleUpload('../images/products/originals/'); if ($products_image['exists'] == true) { if (isset($products_image['filename']) && $products_image['filename'] != null) { $default_flag = 1; $Qcheck = $lC_Database->query('select id from :table_products_images where products_id = :products_id and default_flag = :default_flag limit 1'); $Qcheck->bindTable(':table_products_images', TABLE_PRODUCTS_IMAGES); $Qcheck->bindInt(':products_id', $_GET[$_module]); $Qcheck->bindInt(':default_flag', 1); $Qcheck->execute(); if ($Qcheck->numberOfRows() === 1) { // is default image uploaded, remove the old default image first. if (isset($_GET['default']) && $_GET['default'] == '1') { $lC_Image->delete($Qcheck->value('id')); } else { $default_flag = 0; } } $Qimage = $lC_Database->query('insert into :table_products_images (products_id, image, default_flag, sort_order, date_added) values (:products_id, :image, :default_flag, :sort_order, :date_added)'); $Qimage->bindTable(':table_products_images', TABLE_PRODUCTS_IMAGES); $Qimage->bindInt(':products_id', $_GET[$_module]); $Qimage->bindValue(':image', $products_image['filename']); $Qimage->bindInt(':default_flag', $default_flag); $Qimage->bindInt(':sort_order', 0); $Qimage->bindRaw(':date_added', 'now()'); $Qimage->setLogging($_SESSION['module'], $_GET[$_module]); $Qimage->execute(); foreach ($lC_Image->getGroups() as $group) { if ($group['id'] != '1') { $lC_Image->resize($products_image['filename'], $group['id']); } } } } } $result = array('result' => 1, 'success' => true, 'rpcStatus' => RPC_STATUS_SUCCESS); echo json_encode($result); }
public static function resizeBatch() { global $lC_Database, $lC_Language, $lC_Vqmod; require_once $lC_Vqmod->modCheck('includes/classes/image.php'); $lC_Image_Admin = new lC_Image_Admin(); $overwrite = isset($_GET['overwrite']) && $_GET['overwrite'] == '1' ? true : false; $result = array(); if (!isset($_GET['groups']) || !is_array($_GET['groups'])) { return false; } $Qoriginals = $lC_Database->query('select image from :table_products_images'); $Qoriginals->bindTable(':table_products_images', TABLE_PRODUCTS_IMAGES); $Qoriginals->execute(); $counter = array(); while ($Qoriginals->next()) { foreach ($_GET['groups'] as $groupID) { if ($groupID != '1' && in_array($groupID, $_GET['groups'])) { if (!isset($counter[$groupID])) { $counter[$groupID] = 0; } if ($overwrite === true || !file_exists(DIR_FS_CATALOG . DIR_WS_IMAGES . 'products/' . $group['code'] . '/' . $Qoriginals->value('image'))) { $lC_Image_Admin->resize($Qoriginals->value('image'), $groupID); $counter[$groupID]++; } } } } $cnt = 0; $html = ''; foreach ($counter as $key => $value) { // get group title $Qgroup = $lC_Database->query('select title from :table_products_images_groups where id = :id'); $Qgroup->bindTable(':table_products_images_groups', TABLE_PRODUCTS_IMAGES_GROUPS); $Qgroup->bindInt(':id', $key); $Qgroup->execute(); $class = $cnt % 2 ? 'even' : 'odd'; $html .= '<tr class="' . $class . '">'; $html .= '<td class="dataColResultsGroup"><span>' . $Qgroup->value('title') . '</span></td>'; $html .= '<td class="dataColResultsTotal"><span>' . $value . '</span></td>'; $html .= '</tr>'; $cnt++; } $result['html'] = $html; $Qgroup->freeResult; //remove the resize flag if it exists if (file_exists(DIR_FS_WORK . 'resize.tmp')) { @unlink(DIR_FS_WORK . 'resize.tmp'); } return $result; }