public function service()
 {
     $action = $_REQUEST['action'];
     $itemManager = ItemManager::getInstance($this->config, $this->args);
     switch ($action) {
         case 'find_similar_items':
             $requestedItemId = $this->secure($_REQUEST['item_id']);
             $itemDto = $itemManager->selectByPK($requestedItemId);
             $allItemsMappedArray = $itemManager->getAllItemsTitleAndModelAndBrandMappedArray();
             unset($allItemsMappedArray[$itemDto->getId()]);
             $mostSimillarItemsMappedArray = $this->getItemsSimillarityPercentArrayFromList($itemDto, $allItemsMappedArray);
             $limit = 30;
             $items = array();
             $limitCounter = 0;
             foreach ($mostSimillarItemsMappedArray as $itemId => $percent) {
                 $itemDataArray = $allItemsMappedArray[$itemId];
                 $itemTitle = $itemDataArray[0];
                 $itemCompanyName = $itemDataArray[3];
                 $itemPicturesCount = $itemDataArray[4];
                 $items[] = array($itemId, $itemTitle, $itemCompanyName, $itemPicturesCount);
                 $limitCounter++;
                 if ($limitCounter >= $limit) {
                     break;
                 }
             }
             $this->ok(array('items' => $items));
             break;
         case 'get_item_attributes':
             $itemId = $this->secure($_REQUEST['item_id']);
             $itemDto = $itemManager->selectByPK($itemId);
             $this->ok(array('item' => AbstractDto::dtoToArray($itemDto)));
             break;
         case 'copy_item_pictures':
             $source_item_id = $this->secure($_REQUEST['source_item_id']);
             $target_item_id = $this->secure($_REQUEST['target_item_id']);
             $sourceItemDto = $itemManager->selectByPK($source_item_id);
             $targetItemDto = $itemManager->selectByPK($target_item_id);
             $itemDto = $itemManager->copyItemPictures($sourceItemDto, $targetItemDto);
             $this->ok();
             break;
         case 'copy_item_short_spec':
             $source_item_id = $this->secure($_REQUEST['source_item_id']);
             $target_item_id = $this->secure($_REQUEST['target_item_id']);
             $sourceItemDto = $itemManager->selectByPK($source_item_id);
             $targetItemDto = $itemManager->selectByPK($target_item_id);
             $itemDto = $itemManager->copyItemShortDescription($sourceItemDto, $targetItemDto);
             $this->ok();
             break;
         case 'copy_item_full_spec':
             $source_item_id = $this->secure($_REQUEST['source_item_id']);
             $target_item_id = $this->secure($_REQUEST['target_item_id']);
             $sourceItemDto = $itemManager->selectByPK($source_item_id);
             $targetItemDto = $itemManager->selectByPK($target_item_id);
             $itemDto = $itemManager->copyItemFullDescription($sourceItemDto, $targetItemDto);
             $this->ok();
             break;
         case 'copy_item_model':
             $source_item_id = $this->secure($_REQUEST['source_item_id']);
             $target_item_id = $this->secure($_REQUEST['target_item_id']);
             $sourceItemDto = $itemManager->selectByPK($source_item_id);
             $targetItemDto = $itemManager->selectByPK($target_item_id);
             $itemDto = $itemManager->copyItemModel($sourceItemDto, $targetItemDto);
             $this->ok();
             break;
         default:
             break;
     }
 }
 public function service()
 {
     $action = $_REQUEST['action'];
     $params = array();
     switch ($action) {
         case 'delete_user':
             $this->deleteUser($_REQUEST['user_id']);
             break;
         case 'delete_all_unnecessary_items_pictures':
             $ret = $this->deleteAllUnnecessaryItemsPictures();
             $params = array('removed_items_ids' => implode(',', $ret));
             break;
         case 'set_item_spec':
             $itemId = $_REQUEST['item_id'];
             $shortSpec = $_REQUEST['short_spec'];
             $fullSpec = $_REQUEST['full_spec'];
             require_once CLASSES_PATH . "/managers/ItemManager.class.php";
             $itemManager = ItemManager::getInstance($this->config, $this->args);
             $itemManager->updateTextField($itemId, 'short_description', $shortSpec);
             $itemManager->updateTextField($itemId, 'full_description', $fullSpec);
             break;
         case 'get_item_spec':
             $itemId = $_REQUEST['item_id'];
             require_once CLASSES_PATH . "/managers/ItemManager.class.php";
             $itemManager = ItemManager::getInstance($this->config, $this->args);
             $itemDto = $itemManager->selectByPK($itemId);
             $params['short_spec'] = $itemDto->getShortDescription();
             $params['full_spec'] = $itemDto->getFullDescription();
             break;
         case 'get_camera_1_snap':
             $url = $this->getCmsVar('pcstore_camera_1_url');
             $login = $this->getCmsVar('pcstore_camera_1_login');
             $pass = $this->getCmsVar('pcstore_camera_1_pass');
             $ch = curl_init($url);
             curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
             curl_setopt($ch, CURLOPT_USERPWD, $login . ':' . $pass);
             $img = curl_exec($ch);
             header("Content-Type: image/jpeg");
             echo $img;
             exit;
         case 'filter_emails':
             require_once CLASSES_PATH . "/managers/EmailSenderManager.class.php";
             require_once CLASSES_PATH . "/managers/UninterestingEmailsManager.class.php";
             $emails = $_REQUEST['emails'];
             $emailsArray = EmailSenderManager::getEmailsFromText($emails);
             $uninterestingEmailsManager = UninterestingEmailsManager::getInstance($this->config, $this->args);
             $filteredEmailsArray = $uninterestingEmailsManager->removeUninterestingEmailsFromList($emailsArray);
             $params['count'] = count($filteredEmailsArray);
             $params['emails'] = implode(';', $filteredEmailsArray);
             break;
         case 'is_price_values_ready':
             $companyId = intval($_REQUEST['company_id']);
             require_once CLASSES_PATH . "/managers/PriceTextsManager.class.php";
             $priceTextsManager = PriceTextsManager::getInstance($this->config, $this->args);
             $companyPriceValuesReady = $priceTextsManager->isCompanyPriceValuesReady($companyId);
             $params['ready'] = $companyPriceValuesReady ? '1' : '0';
             break;
         case 'delete_price_values_column':
             $companyId = intval($_REQUEST['company_id']);
             $sheetIndex = intval($_REQUEST['sheet_index']);
             $priceIndex = intval($_REQUEST['price_index']);
             $columnLetter = $this->secure($_REQUEST['column_letter']);
             require_once CLASSES_PATH . "/managers/PriceValuesManager.class.php";
             $priceValuesManager = PriceValuesManager::getInstance($this->config, $this->args);
             $priceValuesManager->moveColumnValuesToLastColumn($companyId, $priceIndex, $sheetIndex, $columnLetter);
             break;
         case 'delete_customer_amessage_after_login':
             $pk = intval($_REQUEST['id']);
             require_once CLASSES_PATH . "/managers/CustomerMessagesAfterLoginManager.class.php";
             $customerMessagesAfterLoginManager = CustomerMessagesAfterLoginManager::getInstance($this->config, $this->args);
             $customerMessagesAfterLoginManager->deleteByPK($pk);
             break;
         case 'preview_customer_message':
             $pk = intval($_REQUEST['id']);
             require_once CLASSES_PATH . "/managers/CustomerMessagesAfterLoginManager.class.php";
             $customerMessagesAfterLoginManager = CustomerMessagesAfterLoginManager::getInstance($this->config, $this->args);
             $dto = $customerMessagesAfterLoginManager->selectByPK($pk);
             $params = AbstractDto::dtoToArray($dto);
             break;
         case 'delete_old_hidden_items':
             $monthsNumber = intval($_REQUEST['months_number']);
             require_once CLASSES_PATH . "/managers/ItemManager.class.php";
             $itemManager = ItemManager::getInstance($this->config, $this->args);
             $params['count'] = $itemManager->deleteOldHiddenItemsByMonthsNumber($monthsNumber);
             break;
         case 'update_companies_price_text':
             $company_id = intval($_REQUEST['company_id']);
             $companyManager = CompanyManager::getInstance($this->config, $this->args);
             if ($company_id == 0) {
                 $allCompanies = $companyManager->getAllCompanies(true, true);
             } else {
                 $allCompanies[] = $companyManager->selectByPK($company_id);
             }
             $cidsArray = array();
             foreach ($allCompanies as $c) {
                 $cidsArray[] = $c->getId();
             }
             $this->updateCompanyPriceText(implode(',', $cidsArray));
             break;
         case 'deploy_latest_pcstore_changes':
             $protocol = "http://";
             if (isset($_SERVER["HTTPS"])) {
                 $protocol = "https://";
             }
             $content = file_get_contents($protocol . HTTP_HOST . '/8350e5a3e24c153df2275c9f80692773.php');
             $params['message'] = $content;
             break;
     }
     $this->ok($params);
 }