/**
  * 	Delete the image on disk
  *
  * @param string $file_path the image file path
  * @param array $image_types The different sizes
  * @param string $parent_path The parent path
  * @return bool
  */
 protected function deleteImageOnDisk($file_path, $image_types = null, $parent_path = null)
 {
     $this->wsObject->setOutputEnabled(false);
     if (file_exists($file_path)) {
         // delete image on disk
         @unlink($file_path);
         // Delete declinated image if needed
         if ($image_types) {
             foreach ($image_types as $image_type) {
                 if ($this->defaultImage) {
                     // @todo products images too !!
                     $declination_path = $parent_path . $this->wsObject->urlSegment[3] . '-default-' . $image_type['name'] . '.jpg';
                 } else {
                     $declination_path = $parent_path . $this->wsObject->urlSegment[2] . '-' . $image_type['name'] . '.jpg';
                 }
                 if (!@unlink($declination_path)) {
                     $this->objOutput->setStatus(204);
                     return false;
                 }
             }
         }
         return true;
     } else {
         $this->objOutput->setStatus(204);
         return false;
     }
 }
예제 #2
0
 /**
  * For a given {id_product, id_product_attribute and id_shop}, gets the stock available id associated
  *
  * @param int $id_product
  * @param int $id_product_attribute Optional
  * @param int $id_shop Optional
  * @return int
  */
 public function updateWs()
 {
     if ($this->depends_on_stock) {
         return WebserviceRequest::getInstance()->setError(500, Tools::displayError('You can\'t update stock available when it\'s depend on stock'));
     }
     return $this->update();
 }
예제 #3
0
 public static function setPermissionForAccount($id_account, $permissions_to_set)
 {
     $ok = true;
     $sql = 'DELETE FROM `' . _DB_PREFIX_ . 'webservice_permission` WHERE `id_webservice_account` = ' . (int) $id_account;
     if (!Db::getInstance()->execute($sql)) {
         $ok = false;
     }
     if (isset($permissions_to_set)) {
         $permissions = array();
         $resources = WebserviceRequest::getResources();
         $methods = array('GET', 'PUT', 'POST', 'DELETE', 'HEAD');
         foreach ($permissions_to_set as $resource_name => $resource_methods) {
             if (in_array($resource_name, array_keys($resources))) {
                 foreach (array_keys($resource_methods) as $method_name) {
                     if (in_array($method_name, $methods)) {
                         $permissions[] = array($method_name, $resource_name);
                     }
                 }
             }
         }
         $account = new WebserviceKey($id_account);
         if ($account->deleteAssociations() && $permissions) {
             $sql = 'INSERT INTO `' . _DB_PREFIX_ . 'webservice_permission` (`id_webservice_permission` ,`resource` ,`method` ,`id_webservice_account`) VALUES ';
             foreach ($permissions as $permission) {
                 $sql .= '(NULL , \'' . pSQL($permission[1]) . '\', \'' . pSQL($permission[0]) . '\', ' . (int) $id_account . '), ';
             }
             $sql = rtrim($sql, ', ');
             if (!Db::getInstance()->execute($sql)) {
                 $ok = false;
             }
         }
     }
     return $ok;
 }
예제 #4
0
 /**
  * For a given {id_product, id_product_attribute and id_shop}, gets the stock available id associated
  *
  * @param int $id_product
  * @param int $id_product_attribute Optional
  * @param int $id_shop Optional
  * @return int
  */
 public function updateWs()
 {
     if ($this->depends_on_stock) {
         return WebserviceRequest::getInstance()->setError(500, Tools::displayError('You cannot update the available stock when it depends on stock.'), 133);
     }
     return $this->update();
 }
 /**
  * Management of search
  *
  */
 public function manage()
 {
     if (!isset($this->wsObject->urlFragments['query']) || !isset($this->wsObject->urlFragments['language'])) {
         throw new WebserviceException('You have to set both the \'language\' and \'query\' parameters to get a result', array(100, 400));
     }
     $objects_products = array();
     $objects_categories = array();
     $objects_products['empty'] = new Product();
     $objects_categories['empty'] = new Category();
     $this->_resourceConfiguration = $objects_products['empty']->getWebserviceParameters();
     if (!$this->wsObject->setFieldsToDisplay()) {
         return false;
     }
     $results = Search::find($this->wsObject->urlFragments['language'], $this->wsObject->urlFragments['query'], 1, 1, 'position', 'desc', true, false);
     $categories = array();
     foreach ($results as $result) {
         $current = new Product($result['id_product']);
         $objects_products[] = $current;
         $categories_result = $current->getWsCategories();
         foreach ($categories_result as $category_result) {
             foreach ($category_result as $id) {
                 $categories[] = $id;
             }
         }
     }
     $categories = array_unique($categories);
     foreach ($categories as $id) {
         $objects_categories[] = new Category($id);
     }
     $this->output .= $this->objOutput->getContent($objects_products, null, $this->wsObject->fieldsToDisplay, $this->wsObject->depth, WebserviceOutputBuilder::VIEW_LIST, false);
     // @todo allow fields of type category and product
     // $this->_resourceConfiguration = $objects_categories['empty']->getWebserviceParameters();
     // if (!$this->setFieldsToDisplay())
     // return false;
     $this->output .= $this->objOutput->getContent($objects_categories, null, $this->wsObject->fieldsToDisplay, $this->wsObject->depth, WebserviceOutputBuilder::VIEW_LIST, false);
 }
예제 #6
0
 public function renderForm()
 {
     $this->fields_form = array('legend' => array('title' => $this->l('Webservice Accounts'), 'icon' => 'icon-lock'), 'input' => array(array('type' => 'textbutton', 'label' => $this->l('Key'), 'name' => 'key', 'id' => 'code', 'required' => true, 'hint' => $this->l('Webservice account key.'), 'button' => array('label' => $this->l('Generate!'), 'attributes' => array('onclick' => 'gencode(32)'))), array('type' => 'textarea', 'label' => $this->l('Key description'), 'name' => 'description', 'rows' => 3, 'cols' => 110, 'hint' => $this->l('Quick description of the key: who it is for, what permissions it has, etc.')), array('type' => 'switch', 'label' => $this->l('Status'), 'name' => 'active', 'required' => false, 'is_bool' => true, 'values' => array(array('id' => 'active_on', 'value' => 1, 'label' => $this->l('Enabled')), array('id' => 'active_off', 'value' => 0, 'label' => $this->l('Disabled')))), array('type' => 'resources', 'label' => $this->l('Permissions'), 'name' => 'resources')));
     if (Shop::isFeatureActive()) {
         $this->fields_form['input'][] = array('type' => 'shop', 'label' => $this->l('Shop association'), 'name' => 'checkBoxShopAsso');
     }
     $this->fields_form['submit'] = array('title' => $this->l('Save'));
     if (!($obj = $this->loadObject(true))) {
         return;
     }
     $ressources = WebserviceRequest::getResources();
     $permissions = WebserviceKey::getPermissionForAccount($obj->key);
     $this->tpl_form_vars = array('ressources' => $ressources, 'permissions' => $permissions);
     return parent::renderForm();
 }
 public function renderForm()
 {
     $this->fields_form = array('legend' => array('title' => $this->l('Webservice Accounts:'), 'image' => '../img/admin/access.png'), 'input' => array(array('type' => 'text', 'label' => $this->l('Key:'), 'name' => 'key', 'id' => 'code', 'size' => 32, 'required' => true, 'desc' => $this->l('Webservice account key')), array('type' => 'textarea', 'label' => $this->l('Key description:'), 'name' => 'description', 'rows' => 3, 'cols' => 110, 'desc' => $this->l('Key description')), array('type' => 'radio', 'label' => $this->l('Status:'), 'name' => 'active', 'required' => false, 'class' => 't', 'is_bool' => true, 'values' => array(array('id' => 'active_on', 'value' => 1, 'label' => $this->l('Enabled')), array('id' => 'active_off', 'value' => 0, 'label' => $this->l('Disabled')))), array('type' => 'resources', 'label' => $this->l('Permissions:'), 'name' => 'resources')));
     if (Shop::isFeatureActive()) {
         $this->fields_form['input'][] = array('type' => 'shop', 'label' => $this->l('Shop association:'), 'name' => 'checkBoxShopAsso');
     }
     $this->fields_form['submit'] = array('title' => $this->l('   Save   '), 'class' => 'button');
     if (!($obj = $this->loadObject(true))) {
         return;
     }
     $ressources = WebserviceRequest::getResources();
     $permissions = WebserviceKey::getPermissionForAccount($obj->key);
     $this->tpl_form_vars = array('ressources' => $ressources, 'permissions' => $permissions);
     return parent::renderForm();
 }
 private function createNewServiceAccount()
 {
     $api_key = Tools::strtoupper(md5(time()));
     $resources = WebserviceRequest::getResources();
     $db_instance = Db::getInstance();
     $db_instance->insert('webservice_account', array('key' => $api_key, 'active' => '1'));
     $account_id = $db_instance->Insert_ID();
     $shop_id = (int) Context::getContext()->shop->id;
     $db_instance->insert('webservice_account_shop', array('id_webservice_account' => $account_id, 'id_shop' => $shop_id));
     $values = array(array('resource' => 'customers', 'method' => 'PUT', 'id_webservice_account' => $account_id));
     foreach (array_keys($resources) as $resource) {
         $values[] = array('resource' => $resource, 'method' => 'GET', 'id_webservice_account' => $account_id);
     }
     $db_instance->insert('webservice_permission', $values);
     Configuration::updateValue('NEWSLETTER2GO_API_KEY', $api_key);
     Configuration::updateValue('NEWSLETTER2GO_API_ACCOUNT', $account_id);
     Configuration::updateValue('PS_WEBSERVICE', 1);
     return $api_key;
 }
 /**
  * @param Array $request Signup/linking account request body.
  * @return Object $requestObject Webservice request object.
  */
 public function getWebserviceRequestObject($request)
 {
     if (isset($request) && !empty($request)) {
         $requestObject = new WebserviceRequest();
         $requestObject->setApiVersion($request['apiVersion']);
         $requestObject->setMethod($request['method']);
         $requestObject->setParams($this->generateParamsObject($request['params']));
         return $requestObject;
     }
 }
예제 #10
0
    public function displayForm($isMainTab = true)
    {
        global $currentIndex;
        parent::displayForm();
        if (!($obj = $this->loadObject(true))) {
            return;
        }
        echo '
		<form action="' . $currentIndex . '&submitAdd' . $this->table . '=1&token=' . $this->token . '" method="post" enctype="multipart/form-data">
		' . ($obj->id ? '<input type="hidden" name="id_' . $this->table . '" value="' . $obj->id . '" />' : '') . '
			<fieldset><legend><img src="../img/admin/access.png" />' . $this->l('Webservice Accounts') . '</legend>
				<label>' . $this->l('Key:') . '</label>
				<div class="margin-form">
					<input type="text" size="32" name="key" id="code" value="' . htmlentities(Tools::getValue('key', $obj->key), ENT_COMPAT, 'UTF-8') . '" />
					<input type="button" value="' . $this->l('   Generate!   ') . '" class="button" onclick="gencode(32)" />
					<sup>*</sup>
					<p class="clear">' . $this->l('Webservice account key') . '</p>
				</div>
				<label>' . $this->l('Key description') . '</label>
				<div class="margin-form">
					<textarea rows="3" style="width:400px" name="description">' . htmlentities(Tools::getValue('description', $obj->description), ENT_COMPAT, 'UTF-8') . '</textarea>
					<p class="clear">' . $this->l('Key description') . '</p>
				</div>
				<label>' . $this->l('Status:') . ' </label>
				<div class="margin-form">
					<input type="radio" name="active" id="active_on" value="1" ' . ((!$obj->id or Tools::getValue('active', $obj->active)) ? 'checked="checked" ' : '') . '/>
					<label class="t" for="active_on"> <img src="../img/admin/enabled.gif" alt="' . $this->l('Enabled') . '" title="' . $this->l('Enabled') . '" /></label>
					<input type="radio" name="active" id="active_off" value="0" ' . ((!Tools::getValue('active', $obj->active) and $obj->id) ? 'checked="checked" ' : '') . '/>
					<label class="t" for="active_off"> <img src="../img/admin/disabled.gif" alt="' . $this->l('Disabled') . '" title="' . $this->l('Disabled') . '" /></label>
				</div>
				<label>' . $this->l('Permissions:') . ' </label>
				<div class="margin-form">
					<p>' . $this->l('Set the resource permissions for this key:') . '</p>
					<table border="0" cellspacing="0" cellpadding="0" class="permissions">
						<thead>
							<tr>
								<th>' . $this->l('Resource') . '</th>
								<th width="30"></th>
								<th width="50">' . $this->l('View (GET)') . '</th>
								<th width="50">' . $this->l('Modify (PUT)') . '</th>
								<th width="50">' . $this->l('Add (POST)') . '</th>
								<th width="50">' . $this->l('Delete (DELETE)') . '</th>
								<th width="50">' . $this->l('Fast view (HEAD)') . '</th>
							</tr>
							
						</thead>
						<tbody>
						<tr class="all" style="vertical-align:cen">
								<th></th>
								<th></th>
								<th><input type="checkbox" class="all_get get " /></th>
								<th><input type="checkbox" class="all_put put " /></th>
								<th><input type="checkbox" class="all_post post " /></th>
								<th><input type="checkbox" class="all_delete delete" /></th>
								<th><input type="checkbox" class="all_head head" /></th>
							</tr>
						';
        $ressources = WebserviceRequest::getResources();
        $permissions = WebserviceKey::getPermissionForAccount($obj->key);
        foreach ($ressources as $resourceName => $resource) {
            echo '
							<tr>
								<th>' . $resourceName . '</th>
								<th><input type="checkbox" class="all"/></th>
								<td><input type="checkbox" ' . (isset($ressources[$resourceName]['forbidden_method']) && in_array('GET', $ressources[$resourceName]['forbidden_method']) ? 'disabled="disabled"' : '') . ' class="get" name="resources[' . $resourceName . '][GET]" ' . (isset($permissions[$resourceName]) && in_array('GET', $permissions[$resourceName]) ? 'checked="checked"' : '') . ' /></td>
								<td><input type="checkbox" ' . (isset($ressources[$resourceName]['forbidden_method']) && in_array('PUT', $ressources[$resourceName]['forbidden_method']) ? 'disabled="disabled"' : '') . ' class="put" name="resources[' . $resourceName . '][PUT]" ' . (isset($permissions[$resourceName]) && in_array('PUT', $permissions[$resourceName]) ? 'checked="checked"' : '') . '/></td>
								<td><input type="checkbox" ' . (isset($ressources[$resourceName]['forbidden_method']) && in_array('POST', $ressources[$resourceName]['forbidden_method']) ? 'disabled="disabled"' : '') . ' class="post" name="resources[' . $resourceName . '][POST]" ' . (isset($permissions[$resourceName]) && in_array('POST', $permissions[$resourceName]) ? 'checked="checked"' : '') . '/></td>
								<td><input type="checkbox" ' . (isset($ressources[$resourceName]['forbidden_method']) && in_array('DELETE', $ressources[$resourceName]['forbidden_method']) ? 'disabled="disabled"' : '') . ' class="delete" name="resources[' . $resourceName . '][DELETE]" ' . (isset($permissions[$resourceName]) && in_array('DELETE', $permissions[$resourceName]) ? 'checked="checked"' : '') . '/></td>
								<td><input type="checkbox" ' . (isset($ressources[$resourceName]['forbidden_method']) && in_array('HEAD', $ressources[$resourceName]['forbidden_method']) ? 'disabled="disabled"' : '') . ' class="head" name="resources[' . $resourceName . '][HEAD]" ' . (isset($permissions[$resourceName]) && in_array('HEAD', $permissions[$resourceName]) ? 'checked="checked"' : '') . '/></td>
							</tr>';
        }
        echo '
						</tbody>
					</table>
					<script>';
        ?>
				
						$(function() {
							$('table.permissions input.all').click(function() {
								if($(this).is(':checked'))
									$(this).parent().parent().find('input.get:not(:checked), input.put:not(:checked), input.post:not(:checked), input.delete:not(:checked), input.head:not(:checked)').click();
								else
									$(this).parent().parent().find('input.get:checked, input.put:checked, input.post:checked, input.delete:checked, input.head:checked').click();
							});
							$('table.permissions .all_get').click(function() {
								if($(this).is(':checked'))
									$(this).parent().parent().parent().find('input.get:not(:checked)').click();
								else
									$(this).parent().parent().parent().find('input.get:checked').click();
							});
							$('table.permissions .all_put').click(function() {
								if($(this).is(':checked'))
									$(this).parent().parent().parent().find('input.put:not(:checked)').click();
								else
									$(this).parent().parent().parent().find('input.put:checked').click();
							});
							$('table.permissions .all_post').click(function() {
								if($(this).is(':checked'))
									$(this).parent().parent().parent().find('input.post:not(:checked)').click();
								else
									$(this).parent().parent().parent().find('input.post:checked').click();
							});
							$('table.permissions .all_delete').click(function() {
								if($(this).is(':checked'))
									$(this).parent().parent().parent().find('input.delete:not(:checked)').click();
								else
									$(this).parent().parent().parent().find('input.delete:checked').click();
							});
							$('table.permissions .all_head').click(function() {
								if($(this).is(':checked'))
									$(this).parent().parent().parent().find('input.head:not(:checked)').click();
								else
									$(this).parent().parent().parent().find('input.head:checked').click();
							});
						});
				<?php 
        echo '
					</script>
				</div>
				<div class="margin-form">
					<input type="submit" value="' . $this->l('   Save   ') . '" name="submitAdd' . $this->table . '" class="button" />
				</div>
				<div class="small"><sup>*</sup> ' . $this->l('Required field') . '</div>
			</fieldset>
		</form>';
    }
예제 #11
0
 /**
  * Display last SQL error
  *
  * @param bool $sql
  */
 public function displayError($sql = false)
 {
     global $webservice_call;
     $errno = $this->getNumberError();
     if ($webservice_call && $errno) {
         WebserviceRequest::getInstance()->setError(500, '[SQL Error] ' . $this->getMsgError() . '. Query was : ' . $sql, 97);
     } else {
         if (_PS_DEBUG_SQL_ && $errno && !defined('PS_INSTALLATION_IN_PROGRESS')) {
             if ($sql) {
                 throw new PrestaShopDatabaseException($this->getMsgError() . '<br /><br /><pre>' . $sql . '</pre>');
             }
             throw new PrestaShopDatabaseException($this->getMsgError());
         }
     }
 }
예제 #12
0
파일: MySQL.php 프로젝트: 7s4r/eBidix
 public function displayMySQLError($query = false)
 {
     global $webservice_call;
     if ($webservice_call && mysql_errno($this->_link)) {
         WebserviceRequest::getInstance()->setError(500, '[SQL Error] ' . mysql_error($this->_link) . '. Query was : ' . $query, 97);
     } elseif (_PS_DEBUG_SQL_ and mysql_errno($this->_link) and !defined('PS_INSTALLATION_IN_PROGRESS')) {
         if ($query) {
             die(Tools::displayError(mysql_error($this->_link) . '<br /><br /><pre>' . $query . '</pre>'));
         }
         die(Tools::displayError(mysql_error($this->_link)));
     }
 }
예제 #13
0
        while ($putData = fread($putresource, 1024)) {
            $input_xml .= $putData;
        }
        fclose($putresource);
    }
}
$params = $_GET;
unset($params['url']);
$class_name = WebserviceKey::getClassFromKey($key);
$bad_class_name = false;
if (!class_exists($class_name)) {
    $class_name = 'WebserviceRequest';
    $bad_class_name = true;
}
// fetch the request
WebserviceRequest::$ws_current_classname = $class_name;
$request = call_user_func(array($class_name, 'getInstance'));
$result = $request->fetch($key, $method, $_GET['url'], $params, $bad_class_name, $input_xml);
// display result
if (ob_get_length() != 0) {
    header('Content-Type: application/javascript');
}
// Useful for debug...
// Manage cache
if (isset($_SERVER['HTTP_LOCAL_CONTENT_SHA1']) && $_SERVER['HTTP_LOCAL_CONTENT_SHA1'] == $result['content_sha1']) {
    $result['status'] = $_SERVER['SERVER_PROTOCOL'] . ' 304 Not Modified';
}
foreach ($result['headers'] as $param_value) {
    header($param_value);
}
if (isset($result['type'])) {
 /**
  * Display last SQL error
  *
  * @param bool $sql
  */
 public function displayError($sql = false)
 {
     global $webservice_call;
     $errno = $this->getNumberError();
     if ($webservice_call && $errno) {
         $dbg = debug_backtrace();
         WebserviceRequest::getInstance()->setError(500, '[SQL Error] ' . $this->getMsgError() . '. From ' . (isset($dbg[3]['class']) ? $dbg[3]['class'] : '') . '->' . $dbg[3]['function'] . '() Query was : ' . $sql, 97);
     } else {
         if (_PS_DEBUG_SQL_ && $errno && !defined('PS_INSTALLATION_IN_PROGRESS')) {
             if ($sql) {
                 throw new PrestaShopDatabaseException($this->getMsgError() . '<br /><br /><pre>' . $sql . '</pre>');
             }
             throw new PrestaShopDatabaseException($this->getMsgError());
         }
     }
 }
예제 #15
0
 /**
  * Used to replace the default PHP error handler, in order to display PHP errors in a XML format
  *
  * @param string $errno contains the level of the error raised, as an integer
  * @param array $errstr contains the error message, as a string
  * @param array $errfile errfile, which contains the filename that the error was raised in, as a string
  * @param array $errline errline, which contains the line number the error was raised at, as an integer
  * @return boolean Always return true to avoid the default PHP error handler
  */
 public function webserviceErrorHandler($errno, $errstr, $errfile, $errline)
 {
     $display_errors = strtolower(ini_get('display_errors')) != 'off';
     if (!(error_reporting() & $errno) || $display_errors) {
         return;
     }
     $errortype = array(E_ERROR => 'Error', E_WARNING => 'Warning', E_PARSE => 'Parse', E_NOTICE => 'Notice', E_CORE_ERROR => 'Core Error', E_CORE_WARNING => 'Core Warning', E_COMPILE_ERROR => 'Compile Error', E_COMPILE_WARNING => 'Compile Warning', E_USER_ERROR => 'Error', E_USER_WARNING => 'User warning', E_USER_NOTICE => 'User notice', E_STRICT => 'Runtime Notice', E_RECOVERABLE_ERROR => 'Recoverable error');
     $type = isset($errortype[$errno]) ? $errortype[$errno] : 'Unknown error';
     error_log('[PHP ' . $type . ' #' . $errno . '] ' . $errstr . ' (' . $errfile . ', line ' . $errline . ')');
     switch ($errno) {
         case E_ERROR:
             WebserviceRequest::getInstance()->setError(500, '[PHP Error #' . $errno . '] ' . $errstr . ' (' . $errfile . ', line ' . $errline . ')', 2);
             break;
         case E_WARNING:
             WebserviceRequest::getInstance()->setError(500, '[PHP Warning #' . $errno . '] ' . $errstr . ' (' . $errfile . ', line ' . $errline . ')', 3);
             break;
         case E_PARSE:
             WebserviceRequest::getInstance()->setError(500, '[PHP Parse #' . $errno . '] ' . $errstr . ' (' . $errfile . ', line ' . $errline . ')', 4);
             break;
         case E_NOTICE:
             WebserviceRequest::getInstance()->setError(500, '[PHP Notice #' . $errno . '] ' . $errstr . ' (' . $errfile . ', line ' . $errline . ')', 5);
             break;
         case E_CORE_ERROR:
             WebserviceRequest::getInstance()->setError(500, '[PHP Core #' . $errno . '] ' . $errstr . ' (' . $errfile . ', line ' . $errline . ')', 6);
             break;
         case E_CORE_WARNING:
             WebserviceRequest::getInstance()->setError(500, '[PHP Core warning #' . $errno . '] ' . $errstr . ' (' . $errfile . ', line ' . $errline . ')', 7);
             break;
         case E_COMPILE_ERROR:
             WebserviceRequest::getInstance()->setError(500, '[PHP Compile #' . $errno . '] ' . $errstr . ' (' . $errfile . ', line ' . $errline . ')', 8);
             break;
         case E_COMPILE_WARNING:
             WebserviceRequest::getInstance()->setError(500, '[PHP Compile warning #' . $errno . '] ' . $errstr . ' (' . $errfile . ', line ' . $errline . ')', 9);
             break;
         case E_USER_ERROR:
             WebserviceRequest::getInstance()->setError(500, '[PHP Error #' . $errno . '] ' . $errstr . ' (' . $errfile . ', line ' . $errline . ')', 10);
             break;
         case E_USER_WARNING:
             WebserviceRequest::getInstance()->setError(500, '[PHP User warning #' . $errno . '] ' . $errstr . ' (' . $errfile . ', line ' . $errline . ')', 11);
             break;
         case E_USER_NOTICE:
             WebserviceRequest::getInstance()->setError(500, '[PHP User notice #' . $errno . '] ' . $errstr . ' (' . $errfile . ', line ' . $errline . ')', 12);
             break;
         case E_STRICT:
             WebserviceRequest::getInstance()->setError(500, '[PHP Strict #' . $errno . '] ' . $errstr . ' (' . $errfile . ', line ' . $errline . ')', 13);
             break;
         case E_RECOVERABLE_ERROR:
             WebserviceRequest::getInstance()->setError(500, '[PHP Recoverable error #' . $errno . '] ' . $errstr . ' (' . $errfile . ', line ' . $errline . ')', 14);
             break;
         default:
             WebserviceRequest::getInstance()->setError(500, '[PHP Unknown error #' . $errno . '] ' . $errstr . ' (' . $errfile . ', line ' . $errline . ')', 15);
     }
     return true;
 }
예제 #16
0
 /**
  * Used to replace the default PHP error handler, in order to display PHP errors in a XML format 
  *
  * @param string $errno contains the level of the error raised, as an integer
  * @param array $errstr contains the error message, as a string
  * @param array $errfile errfile, which contains the filename that the error was raised in, as a string
  * @param array $errline errline, which contains the line number the error was raised at, as an integer
  * @return boolean Always return true to avoid the default PHP error handler
  */
 public function webserviceErrorHandler($errno, $errstr, $errfile, $errline)
 {
     if (!(error_reporting() & $errno)) {
         return;
     }
     switch ($errno) {
         case E_ERROR:
             WebserviceRequest::getInstance()->setError(500, '[PHP Error #' . $errno . '] ' . $errstr . ' (' . $errfile . ', line ' . $errline . ')', 2);
             break;
         case E_WARNING:
             WebserviceRequest::getInstance()->setError(500, '[PHP Warning #' . $errno . '] ' . $errstr . ' (' . $errfile . ', line ' . $errline . ')', 3);
             break;
         case E_PARSE:
             WebserviceRequest::getInstance()->setError(500, '[PHP Parse #' . $errno . '] ' . $errstr . ' (' . $errfile . ', line ' . $errline . ')', 4);
             break;
         case E_NOTICE:
             WebserviceRequest::getInstance()->setError(500, '[PHP Notice #' . $errno . '] ' . $errstr . ' (' . $errfile . ', line ' . $errline . ')', 5);
             break;
         case E_CORE_ERROR:
             WebserviceRequest::getInstance()->setError(500, '[PHP Core #' . $errno . '] ' . $errstr . ' (' . $errfile . ', line ' . $errline . ')', 6);
             break;
         case E_CORE_WARNING:
             WebserviceRequest::getInstance()->setError(500, '[PHP Core warning #' . $errno . '] ' . $errstr . ' (' . $errfile . ', line ' . $errline . ')', 7);
             break;
         case E_COMPILE_ERROR:
             WebserviceRequest::getInstance()->setError(500, '[PHP Compile #' . $errno . '] ' . $errstr . ' (' . $errfile . ', line ' . $errline . ')', 8);
             break;
         case E_COMPILE_WARNING:
             WebserviceRequest::getInstance()->setError(500, '[PHP Compile warning #' . $errno . '] ' . $errstr . ' (' . $errfile . ', line ' . $errline . ')', 9);
             break;
         case E_USER_ERROR:
             WebserviceRequest::getInstance()->setError(500, '[PHP Error #' . $errno . '] ' . $errstr . ' (' . $errfile . ', line ' . $errline . ')', 10);
             break;
         case E_USER_WARNING:
             WebserviceRequest::getInstance()->setError(500, '[PHP User warning #' . $errno . '] ' . $errstr . ' (' . $errfile . ', line ' . $errline . ')', 11);
             break;
         case E_USER_NOTICE:
             WebserviceRequest::getInstance()->setError(500, '[PHP User notice #' . $errno . '] ' . $errstr . ' (' . $errfile . ', line ' . $errline . ')', 12);
             break;
         case E_STRICT:
             WebserviceRequest::getInstance()->setError(500, '[PHP Strict #' . $errno . '] ' . $errstr . ' (' . $errfile . ', line ' . $errline . ')', 13);
             break;
         case E_RECOVERABLE_ERROR:
             WebserviceRequest::getInstance()->setError(500, '[PHP Recoverable error #' . $errno . '] ' . $errstr . ' (' . $errfile . ', line ' . $errline . ')', 14);
             break;
         default:
             WebserviceRequest::getInstance()->setError(500, '[PHP Unknown error #' . $errno . '] ' . $errstr . ' (' . $errfile . ', line ' . $errline . ')', 15);
     }
     return true;
 }
예제 #17
0
    $class_name = 'WebserviceRequest';
    $bad_class_name = true;
}
// fetch the request
$request = call_user_func(array($class_name, 'getInstance'));
$result = $request->fetch($key, $method, $_GET['url'], $params, $bad_class_name, $input_xml);
// display result
if (ob_get_length() == 0) {
    header($result['content_type']);
} else {
    header('Content-Type: application/javascript');
}
// Useful for debug...
header($result['status']);
header($result['x_powered_by']);
header($result['execution_time']);
if (isset($result['ps_ws_version'])) {
    header($result['ps_ws_version']);
}
if ($result['type'] == 'xml') {
    header($result['content_sha1']);
    echo $result['content'];
} elseif ($result['type'] == 'image') {
    if ($result['content_type'] == 'Content-Type: image/jpeg') {
        imagejpeg(WebserviceRequest::getInstance()->_imageResource);
    } elseif ($result['content_type'] == 'Content-Type: image/gif') {
        imagegif(WebserviceRequest::getInstance()->_imageResource);
    }
    imagedestroy(WebserviceRequest::getInstance()->_imageResource);
}
ob_end_flush();
예제 #18
0
파일: Product.php 프로젝트: yewed/share
    /**
     * Webservice setter : set virtual field position in category
     *
     * @return bool
     */
    public function setWsPositionInCategory($position)
    {
        if ($position < 0) {
            WebserviceRequest::getInstance()->setError(500, Tools::displayError('You cannot set a negative position, the minimum for a position is 0.'), 134);
        }
        $result = Db::getInstance()->executeS('
			SELECT `id_product`
			FROM `' . _DB_PREFIX_ . 'category_product`
			WHERE `id_category` = ' . (int) $this->id_category_default . '
			ORDER BY `position`
		');
        if ($position > 0 && $position + 1 > count($result)) {
            WebserviceRequest::getInstance()->setError(500, Tools::displayError('You cannot set a position greater than the total number of products in the category, minus 1 (position numbering starts at 0).'), 135);
        }
        foreach ($result as &$value) {
            $value = $value['id_product'];
        }
        $current_position = $this->getWsPositionInCategory();
        if ($current_position && isset($result[$current_position])) {
            $save = $result[$current_position];
            unset($result[$current_position]);
            array_splice($result, (int) $position, 0, $save);
        }
        foreach ($result as $position => $id_product) {
            Db::getInstance()->update('category_product', array('position' => $position), '`id_category` = ' . (int) $this->id_category_default . ' AND `id_product` = ' . (int) $id_product);
        }
        return true;
    }
 /**
  * Check resource validity
  *
  * @return boolean
  */
 private function checkResource()
 {
     $this->_resourceList = WebserviceRequest::getResources();
     $resourceNames = array_keys($this->_resourceList);
     if ($this->_urlSegment[0] == '') {
         $this->_resourceConfiguration['objectsNodeName'] = 'resources';
     } elseif (in_array($this->_urlSegment[0], $resourceNames)) {
         if (!in_array($this->_urlSegment[0], array_keys($this->_keyPermissions))) {
             $this->setError(401, 'Resource of type "' . $this->_urlSegment[0] . '" is not allowed with this authentication key');
             return false;
         }
     } else {
         $this->setErrorDidYouMean(400, 'Resource of type "' . $this->_urlSegment[0] . '" does not exists', $this->_urlSegment[0], $resourceNames);
         return false;
     }
     return true;
 }
예제 #20
0
    /**
     * Set customized text fields
     * (for webservice)
     *
     * @param array $values
     *
     * @return bool
     */
    public function setWsCustomizedDataTextFields($values)
    {
        $cart = new Cart($this->id_cart);
        if (!Validate::isLoadedObject($cart)) {
            WebserviceRequest::getInstance()->setError(500, Tools::displayError('Could not load cart id=' . $this->id_cart), 137);
            return false;
        }
        Db::getInstance()->execute('
		DELETE FROM `' . _DB_PREFIX_ . 'customized_data`
		WHERE id_customization = ' . (int) $this->id . '
		AND type = 1');
        foreach ($values as $value) {
            $query = 'INSERT INTO `' . _DB_PREFIX_ . 'customized_data` (`id_customization`, `type`, `index`, `value`)
				VALUES (' . (int) $this->id . ', 1, ' . (int) $value['id_customization_field'] . ', \'' . pSQL($value['value']) . '\')';
            if (!Db::getInstance()->execute($query)) {
                return false;
            }
        }
        return true;
    }