Пример #1
0
 /**
  * Admin search function
  *
  * @param string $type
  * @param string $search_string
  * @return data/false
  */
 public static function search($type, $search_string)
 {
     $data = false;
     if (!empty($type) && !empty($search_string)) {
         switch (strtolower($type)) {
             case 'user':
                 if (($results = $GLOBALS['db']->select('CubeCart_customer', false, array('~' . $search_string => array('last_name', 'first_name', 'email')), false, false, false, false)) !== false) {
                     foreach ($results as $result) {
                         $data[] = array('value' => $result['customer_id'], 'display' => $result['first_name'] . ' ' . $result['last_name'], 'info' => $result['email'], 'data' => $result);
                     }
                 }
                 break;
             case 'address':
                 if (($results = $GLOBALS['db']->select('CubeCart_addressbook', false, array('customer_id' => (int) $search_string), false, false, false, false)) !== false) {
                     foreach ($results as $result) {
                         $result['state'] = getStateFormat($result['state']);
                         $result['country'] = getCountryFormat($result['country']);
                         $data[] = $result;
                     }
                 }
                 break;
             case 'product':
                 // Limited to a maximum of 15 results, in order to prevent it going mental
                 if (($results = $GLOBALS['db']->select('CubeCart_inventory', false, array('~' . $search_string => array('name', 'product_code')), false, 15, false, false)) !== false) {
                     foreach ($results as $result) {
                         $lower_price = Tax::getInstance()->salePrice($result['price'], $result['sale_price'], false);
                         if ($lower_price && $lower_price < $result['price']) {
                             $result['price'] = $lower_price;
                         }
                         $data[] = array('value' => $result['product_id'], 'display' => $result['name'], 'info' => Tax::getInstance()->priceFormat($result['price']), 'data' => $result);
                     }
                 }
                 break;
             case 'newsletter':
                 $newsletter = Newsletter::getInstance();
                 $status = $newsletter->sendNewsletter($_GET['q'], $_GET['page']);
                 if (is_array($status)) {
                     $data = $status;
                 } else {
                     $data = $status ? array('complete' => 'true', 'percent' => 100) : array('error' => 'true');
                 }
                 break;
             case 'files':
                 if ($_GET['dir'] == '/') {
                     $dir = false;
                 } elseif ($_GET['dir'] == '/') {
                     $dir = false;
                 } else {
                     $dir = $_GET['dir'];
                 }
                 $filemanager = new FileManager($_GET['group'], $dir);
                 // Directories
                 if (($dirs = $filemanager->findDirectories()) !== false) {
                     foreach ($dirs[$filemanager->formatPath($dir)] as $parent => $folder) {
                         $path = !empty($dir) ? '/' : '';
                         $json[] = array('type' => 'directory', 'path' => urldecode($dir . basename($folder) . '/'), 'name' => basename($folder));
                     }
                 }
                 if (($files = $filemanager->listFiles()) !== false) {
                     $catalogue = new Catalogue();
                     foreach ($files as $result) {
                         if ($filemanager->getMode() == FileManager::FM_FILETYPE_IMG) {
                             $fetch = $catalogue->imagePath($result['file_id'], 'medium');
                             $path = $name = $fetch;
                         } else {
                             $path = $result['filepath'];
                             $name = $result['filename'];
                         }
                         $json[] = array('type' => 'file', 'path' => dirname($path) . '/', 'file' => basename($result['filename']), 'name' => basename($name), 'id' => $result['file_id'], 'description' => $result['description'], 'mime' => $result['mimetype']);
                     }
                 }
                 $data = isset($json) && is_array($json) ? $json : false;
                 break;
             default:
                 return false;
                 break;
         }
         if (!$data) {
             $data = array();
         }
         return json_encode($data);
     }
     return false;
 }
Пример #2
0
 /**
  * List file type
  *
  * @param string $type
  * @param bool $select_button
  * @return array/false
  */
 public function listFiles($type = false, $select_button = false)
 {
     // Display Breadcrumbs
     if (!empty($this->_sub_dir)) {
         $elements = explode('/', $this->_sub_dir);
         if ($elements) {
             foreach ($elements as $sub_dir) {
                 $path[] = $sub_dir;
                 $GLOBALS['gui']->addBreadcrumb($sub_dir, currentPage(null, array('subdir' => $this->formatPath(implode('/', $path), false))));
             }
         }
     }
     $type_desc = $this->_mode == self::FM_FILETYPE_IMG ? $GLOBALS['language']->filemanager['file_type_image'] : $GLOBALS['language']->filemanager['file_type_dl'];
     $GLOBALS['smarty']->assign('FILMANAGER_TITLE', $type_desc . " Filemanager");
     $GLOBALS['smarty']->assign('FILMANAGER_MODE', (string) $this->_mode);
     // Create a backlink to the parent directory, if is exists
     if ($this->_directories && isset($this->_directories[$this->formatPath($this->_sub_dir)])) {
         // List subdirectories
         foreach ($this->_directories[$this->formatPath($this->_sub_dir)] as $dir) {
             if ($this->_mode == self::FM_FILETYPE_IMG && in_array($this->makeFilename($dir), array('thumbs', 'source'))) {
                 continue;
             }
             $name = $this->makeFilename($dir);
             $folder = array('name' => $name, 'link' => currentPage(null, array('subdir' => $this->formatPath($this->_sub_dir . $dir, false))), 'delete' => substr($name, 0, 1) !== '.' ? currentPage(null, array('delete' => $this->formatPath($this->_sub_dir . $dir, false))) : null);
             $list_folders[] = $folder;
         }
         $GLOBALS['smarty']->assign('FOLDERS', $list_folders);
     }
     $filepath_where = empty($this->_sub_dir) ? 'IS NULL' : '= \'' . str_replace('\\', '/', $this->_sub_dir) . '\'';
     $where = '`disabled` = 0 AND `type` = ' . (int) $this->_mode . ' AND `filepath` ' . $filepath_where;
     if (($files = $GLOBALS['db']->select('CubeCart_filemanager', false, $where, array('filename' => 'ASC'))) !== false) {
         $catalogue = new Catalogue();
         $GLOBALS['smarty']->assign('ROOT_REL', $GLOBALS['rootRel']);
         foreach ($files as $key => $file) {
             $file['icon'] = $this->getFileIcon($file['mimetype']);
             $file['class'] = preg_match('#^image#', $file['mimetype']) ? 'class="colorbox"' : '';
             $file['edit'] = currentPage(null, array('fm-edit' => $file['file_id']));
             $file['delete'] = currentPage(null, array('delete' => $file['file_id']));
             $file['random'] = mt_rand();
             $file['description'] = !empty($file['description']) ? $file['description'] : $file['filename'];
             $file['master_filepath'] = str_replace(chr(92), "/", $this->_manage_dir . '/' . $file['filepath'] . $file['filename']);
             $file['filepath'] = $this->_mode == self::FM_FILETYPE_IMG ? $catalogue->imagePath($file['file_id'], 'medium') : $this->_manage_dir . '/' . $file['filepath'] . $file['filename'];
             $file['select_button'] = (bool) $select_button;
             if ($select_button) {
                 $file['master_filepath'] = $GLOBALS['rootRel'] . $file['master_filepath'];
             }
             // Fix the image path added to the FCK editor area
             $list_files[$key] = $file;
         }
         $GLOBALS['smarty']->assign('FILES', $list_files);
         return $list_files;
     }
     return false;
 }