public function postExecute($params = null, $result = null)
 {
     if (is_array($params)) {
         $order_id = $params['order_id'];
     } else {
         $order_id = $params;
     }
     $data = parent::postExecute($order_id, $result);
     $order_model = new shopOrderModel();
     if (is_array($order_id)) {
         $order = $order_id;
         $order_id = $order['id'];
     } else {
         $order = $order_model->getById($order_id);
     }
     shopCustomers::recalculateTotalSpent($order['contact_id']);
     if ($order !== null) {
         $order_model->recalculateProductsTotalSales($order_id);
     }
     $log_model = new shopOrderLogModel();
     $state_id = $log_model->getPreviousState($order_id);
     $app_settings_model = new waAppSettingsModel();
     $update_on_create = $app_settings_model->get('shop', 'update_stock_count_on_create_order');
     if (!$update_on_create && $state_id == 'new') {
         // for logging changes in stocks
         shopProductStocksLogModel::setContext(shopProductStocksLogModel::TYPE_ORDER, _w('Order %s was paid'), array('order_id' => $order_id));
         // jump through 'processing' state - reduce
         $order_model = new shopOrderModel();
         $order_model->reduceProductsFromStocks($order_id);
         shopProductStocksLogModel::clearContext();
     }
     return $data;
 }
 public function save(waRequestFile $file, $data)
 {
     // check image
     if (!($image = $file->waImage())) {
         throw new waException(_w('Incorrect image'));
     }
     $plugin = wa()->getPlugin('publicgallery');
     $min_size = $plugin->getSettings('min_size');
     if ($min_size && ($image->height < $min_size || $image->width < $min_size)) {
         throw new waException(sprintf(_w("Image is too small. Minimum image size is %d px"), $min_size));
     }
     $max_size = $plugin->getSettings('max_size');
     if ($max_size && ($image->height > $max_size || $image->width > $max_size)) {
         throw new waException(sprintf(_w("Image is too big. Maximum image size is %d px"), $max_size));
     }
     $id = $this->model->add($file, $data);
     if (!$id) {
         throw new waException(_w("Save error"));
     }
     $tag = $plugin->getSettings('assign_tag');
     if ($tag) {
         $photos_tag_model = new photosPhotoTagsModel();
         $photos_tag_model->set($id, $tag);
     }
     return array('name' => $file->name, 'type' => $file->type, 'size' => $file->size);
 }
 protected function getContactData()
 {
     if (!$this->author->isAuth()) {
         throw new waException(_w('Access denied'));
     }
     return parent::getContactData();
 }
 public function execute()
 {
     if (!$this->getUser()->isAdmin('photos')) {
         throw new waException(_w('Access denied'));
     }
     $this->view->assign('plugins', $this->getConfig()->getPlugins());
 }
 public function execute()
 {
     if (!$this->getUser()->getRights('shop', 'settings')) {
         throw new waRightsException(_w('Access denied'));
     }
     $model = new shopTypeModel();
     $data = array();
     $data['id'] = waRequest::post('id', 0, waRequest::TYPE_INT);
     switch (waRequest::post('source', 'custom')) {
         case 'custom':
             $data['name'] = waRequest::post('name');
             $data['icon'] = waRequest::post('icon_url', false, waRequest::TYPE_STRING_TRIM);
             if (empty($data['icon'])) {
                 $data['icon'] = waRequest::post('icon', 'icon.box', waRequest::TYPE_STRING_TRIM);
             }
             if (!empty($data['id'])) {
                 $model->updateById($data['id'], $data);
             } else {
                 $data['sort'] = $model->select('MAX(sort)+1 as max_sort')->fetchField('max_sort');
                 $data['id'] = $model->insert($data);
             }
             break;
         case 'template':
             $data = $model->insertTemplate(waRequest::post('template'), true);
             break;
     }
     if ($data) {
         $data['icon_html'] = shopHelper::getIcon($data['icon'], 'icon.box');
         $data['name_html'] = '<span class="js-type-icon">' . $data['icon_html'] . '</span>
                 <span class="js-type-name">' . htmlspecialchars($data['name'], ENT_QUOTES, 'utf-8') . '</span>';
     }
     $this->response = $data;
 }
 public function execute()
 {
     $photo_id = waRequest::get('photo_id', array(), waRequest::TYPE_ARRAY_INT);
     if (!$photo_id) {
         throw new waException(_w('Empty photo list'));
     }
     $photo_model = new photosPhotoModel();
     // dialog for one photo
     if (count($photo_id) == 1) {
         $photo_id = current($photo_id);
         $photo = $photo_model->getById($photo_id);
         $photo_right_model = new photosPhotoRightsModel();
         if (!$photo_right_model->checkRights($photo, true)) {
             $rights = array(0 => array('group_id' => 0, 'photo_id' => null));
         } else {
             $rights = $photo_right_model->getByField('photo_id', $photo_id, 'group_id');
         }
     } else {
         // dialog for several selected photos
         // dummies for correct template randering
         $photo = array('status' => 1);
         $rights = array(0 => array('group_id' => 0, 'photo_id' => null));
         $allowed_photo_id = (array) $photo_model->filterByField($photo_id, 'status', 1);
         $this->view->assign('photo_count', count($photo_id));
         $this->view->assign('disable_submit', count($allowed_photo_id) != count($photo_id));
     }
     $groups_model = new waGroupModel();
     $groups = $groups_model->getAll('id', true);
     $this->view->assign('groups', $groups);
     $this->view->assign('photo', $photo);
     $this->view->assign('rights', $rights);
 }
 public function move($id, $after_id)
 {
     try {
         $sheet = $this->getById($id);
         if (!$sheet) {
             return array('error' => _w("Board not found"));
         }
         if ($after_id != 0) {
             $after_sheet = $this->getById($after_id);
             if (!$after_sheet) {
                 return array('error' => _w("Board not found"));
             }
             $sort = $after_sheet['sort'] + 1;
             // insert after sticky ()
         } else {
             $sort = 1;
         }
         if ($sort > $sheet['sort']) {
             $this->exec("UPDATE {$this->table} SET sort = sort - 1 WHERE sort > i:sort_old AND sort <= i:sort", array('sort' => $sort, 'sort_old' => $sheet['sort']));
         } else {
             if ($sort < $sheet['sort']) {
                 $this->exec("UPDATE {$this->table} SET sort = sort + 1 WHERE sort >= i:sort AND sort < i:sort_old", array('sort' => $sort, 'sort_old' => $sheet['sort']));
             }
         }
         $this->updateById($id, array('sort' => (int) $sort));
     } catch (waDbException $e) {
         return array('error' => $e->getMessage());
     }
     return array();
 }
 public function execute()
 {
     if (!$this->getUser()->getRights('photos', 'edit')) {
         throw new waException(_w("Access denied"));
     }
     $moderation = waRequest::post('moderation', '', waRequest::TYPE_STRING_TRIM);
     $id = waRequest::post('id', '', waRequest::TYPE_INT);
     $photo_model = new photosPhotoModel();
     $photo = $photo_model->getById($id);
     if (!$photo) {
         $this->errors[] = _wp('Unknown photo');
     }
     if ($moderation == 'approve') {
         $photo_model->updateById($id, array('moderation' => 1));
         $photo_model->updateAccess($id, 1, array(0));
     }
     if ($moderation == 'decline') {
         $photo_model->updateById($id, array('moderation' => -1));
         $photo_model->updateAccess($id, 0, array(0));
     }
     $this->response['photo'] = $photo_model->getById($id);
     // update for making inline-editable widget
     $this->response['frontend_link_template'] = photosFrontendPhoto::getLink(array('url' => '%url%'));
     $this->response['counters'] = array('declined' => $photo_model->countByField('moderation', -1), 'awaiting' => $photo_model->countByField('moderation', 0));
     // l18n string
     $count = (int) waRequest::post('count');
     $total_count = (int) waRequest::post('total_count');
     $this->response['string'] = array('loaded' => _w('%d photo', '%d photos', $count), 'of' => sprintf(_w('of %d'), $total_count), 'chunk' => $count < $total_count ? _w('%d photo', '%d photos', min($this->getConfig()->getOption('photos_per_page'), $count - $total_count)) : false);
 }
 public function execute()
 {
     $path = rtrim(waRequest::post('path'), ' /');
     $path = wa()->getDataPath($path, true, null, false);
     $hash = $new_path = waRequest::post('new_path');
     $new_path = wa()->getDataPath($new_path, true, null, false) . ($new_path ? '' : '/');
     if (!is_writable($new_path)) {
         $this->errors = sprintf(_w("Files could not bet moved due to the insufficient file write permissions for the %s folder."), rtrim($hash, '/'));
         return;
     }
     if ($file = waRequest::post('file')) {
         if (!is_array($file)) {
             $file = array($file);
         }
         foreach ($file as $f) {
             if (!@rename($path . "/" . $f, $new_path . $f)) {
                 $this->errors[] = sprintf(_w("Can not move file “%s” to a new location"), $f);
             }
         }
         if ($this->errors && is_array($this->errors)) {
             $this->errors = implode(";\r\n", $this->errors);
         }
     } else {
         $new_path .= basename($path);
         $hash .= basename($path) . "/";
         if (@rename($path, $new_path)) {
             $this->response['hash'] = $hash;
         } else {
             $this->errors = _w("Can not move to a new location");
         }
     }
 }
 public function execute()
 {
     $name = waRequest::post('name', '', waRequest::TYPE_STRING_TRIM);
     if (in_array($name, $this->availableFields) === false) {
         throw new waException(_w("Can't update album: unknown field"));
     }
     $album_rights_model = new photosAlbumRightsModel();
     $id = waRequest::post('id', null, waRequest::TYPE_ARRAY_INT);
     if (is_array($id)) {
         $id = current($id);
     }
     if ($id) {
         $album_model = new photosAlbumModel();
         $album = $album_model->getById($id);
         if (!$album) {
             throw new waException(_w('Unknown album'));
         }
         if (!$album_rights_model->checkRights($album, true)) {
             throw new waException(_w("You don't have sufficient access rights"));
         }
         $value = waRequest::post('value', '', waRequest::TYPE_STRING_TRIM);
         $album_model->updateById($id, array($name => $value));
         $album['not_escaped_name'] = $value;
         $album['name'] = photosPhoto::escape($value);
         $this->response['album'] = $album;
     }
 }
Beispiel #11
0
 public static function formatValue($c, $curr = null)
 {
     static $currencies = null;
     if ($currencies === null) {
         if ($curr) {
             $currencies = $curr;
         } else {
             $curm = new shopCurrencyModel();
             $currencies = $curm->getAll('code');
         }
     }
     if ($c['type'] == '$FS') {
         return _w('Free shipping');
     } else {
         if ($c['type'] === '%') {
             return waCurrency::format('%0', $c['value'], 'USD') . '%';
         } else {
             if (!empty($currencies[$c['type']])) {
                 return waCurrency::format('%0{s}', $c['value'], $c['type']);
             } else {
                 // Coupon of unknown type. Possibly from a plugin?..
                 return '';
             }
         }
     }
 }
 public function payment($data, $order_data, $auto_submit = false)
 {
     $data['order_id'] = $order_data['order_id'];
     if ($order_data['currency_id'] != 'USD') {
         throw new waPaymentException(_w('Order currency is not USD but payment gateway provide only USD transactions'));
     }
     $type_trans = array_flip(self::$type_trans);
     if (!empty($data['type']) && !empty($type_trans[$data['type']])) {
         $type = $type_trans[$data['type']];
     } else {
         $type = self::OPERATION_AUTH_ONLY;
     }
     if (empty($order_data['description_en'])) {
         $order_data['description_en'] = 'Order #' . $order_data['order_id'] . ' (' . gmdate('F, d Y') . ')';
     }
     $c = new waContact($order_data['contact_id']);
     $locale = $c->getLocale();
     $form_fields = array('x_login' => $this->login, 'x_amount' => number_format($order_data['amount'], 2, '.', ''), 'x_description' => $order_data['description_en'], 'x_invoice_num' => $order_data['order_id'], 'x_fp_sequence' => rand(1, 1000), 'x_fp_timestamp' => time(), 'x_test_request' => 'false', 'x_show_form' => 'PAYMENT_FORM', 'x_type' => $type, 'x_version' => '3.1', 'x_method' => 'CC', 'x_cust_id' => $order_data['contact_id'], 'x_customer_ip' => wa()->getRequest()->server('REMOTE_ADDR'), 'x_duplicate_window' => '28800', 'x_first_name' => waLocale::transliterate($c->get('firstname'), $locale), 'x_last_name' => waLocale::transliterate($c->get('lastname'), $locale), 'x_company' => waLocale::transliterate($c->get('company'), $locale), 'x_address' => waLocale::transliterate($c->get('address:street', 'default'), $locale), 'x_city' => waLocale::transliterate($c->get('address:city', 'default'), $locale), 'x_state' => waLocale::transliterate($c->get('address:region', 'default'), $locale), 'x_zip' => waLocale::transliterate($c->get('address:zip', 'default'), $locale), 'x_country' => waLocale::transliterate($c->get('address:country', 'default'), $locale), 'x_phone' => $c->get('phone', 'default'), 'x_email' => $c->get('email', 'default'), 'x_relay_response' => isset($data['x_relay_response']) ? $data['x_relay_response'] : 'true', 'x_relay_url' => $this->getRelayUrl(), 'wa_success_url' => $this->getAdapter()->getBackUrl(waAppPayment::URL_SUCCESS, $data), 'wa_decline_url' => $this->getAdapter()->getBackUrl(waAppPayment::URL_DECLINE, $data), 'wa_cancel_url' => $this->getAdapter()->getBackUrl(waAppPayment::URL_FAIL, $data), 'wa_app_id' => $this->app_id, 'wa_merchant_id' => $this->merchant_id);
     $form_fields['x_fp_hash'] = '';
     // @TODO: get from common 'address' field
     if (phpversion() >= '5.1.2') {
         $form_fields['x_fp_hash'] = hash_hmac('md5', $this->login . "^" . $form_fields['x_fp_sequence'] . "^" . $form_fields['x_fp_timestamp'] . "^" . $form_fields['x_amount'] . "^", $this->trans_key);
     } else {
         $form_fields['x_fp_hash'] = bin2hex(mhash(MHASH_MD5, $this->login . "^" . $form_fields['x_fp_sequence'] . "^" . $form_fields['x_fp_timestamp'] . "^" . $form_fields['x_amount'] . "^", $this->trans_key));
     }
     if ($this->form_header) {
         $form_fields['x_header_html_payment_form'] = $this->form_header;
     }
     $view = wa()->getView();
     $view->assign('url', wa()->getRootUrl());
     $view->assign('form_fields', $form_fields);
     $view->assign('form_url', $this->getEndpointUrl());
     $view->assign('auto_submit', $auto_submit);
     return $view->fetch($this->path . '/templates/payment.html');
 }
 public function execute()
 {
     $ids = waRequest::request('id', array(), 'array_int');
     if (!$ids) {
         throw new waException('Contact id not specified.');
     }
     // only allowed to global admin
     if (!wa()->getUser()->getRights('webasyst', 'backend')) {
         throw new waRightsException(_w('Access denied'));
     }
     $groups = waRequest::post('groups', array(), 'array_int');
     $counters = array();
     $ugm = new waUserGroupsModel();
     if ($this->getRequest()->request('set')) {
         foreach ($ids as $id) {
             $ugm->delete($id, array());
         }
     }
     foreach ($ids as $id) {
         if ($groups) {
             $ugm->add(array_map(wa_lambda('$gid', 'return array(' . $id . ', $gid);'), $groups));
         }
     }
     $gm = new waGroupModel();
     foreach ($groups as $gid) {
         $cnt = $ugm->countByField(array('group_id' => $gid));
         $gm->updateCount($gid, $cnt);
         $counters[$gid] = $cnt;
     }
     $this->response['counters'] = $counters;
     $this->response['message'] = _w("%d user has been added", "%d users have been added", count($ids));
     $this->response['message'] .= ' ';
     $this->response['message'] .= _w("to %d group", "to %d groups", count($groups));
 }
 public function execute()
 {
     $filter = array();
     $filter['enabled'] = true;
     $filter['extras'] = 'plugins';
     $options = array('installed' => true);
     $search = array();
     $search['slug'] = preg_replace('@^(wa-plugins/)?([^/]+)/.+$@', '$1$2', waRequest::get('slug'));
     if (strpos($search['slug'], 'wa-plugins/') === 0) {
         $options['system'] = true;
     }
     $applications = installerHelper::getInstaller()->getApps($options, $filter);
     $plugin_search = array();
     $plugin_search['id'] = preg_replace('@^.+/@', '', waRequest::get('slug'));
     if (array_filter($search, 'strlen') && ($app = installerHelper::search($applications, $search))) {
         $plugin_search['slug'] = $search['slug'] . "/plugins/" . $plugin_search['id'];
         $options = array('action' => true, 'requirements' => true);
         $plugin = installerHelper::getInstaller()->getItemInfo($plugin_search['slug'], $options);
         if (!$plugin) {
             $options['local'] = true;
             $plugin = installerHelper::getInstaller()->getItemInfo($plugin_search['slug'], $options);
         }
         if ($plugin) {
             $plugin['app'] = preg_replace('@^(wa-plugins/)?([^/]+)/.+$@', '$1$2', $plugin['slug']);
             $plugin['slug'] = preg_replace('@^wa-plugins/([^/]+)/plugins/(.+)$@', 'wa-plugins/$1/$2', $plugin['slug']);
         }
         $this->view->assign('identity_hash', installerHelper::getHash());
         $this->view->assign('promo_id', installerHelper::getPromoId());
         $this->view->assign('domain', installerHelper::getDomain());
         $this->view->assign('plugin', $plugin);
         $this->view->assign('query', waRequest::get('query', '', waRequest::TYPE_STRING_TRIM) . '/');
     } else {
         throw new waException(_w('Plugin not found'), 404);
     }
 }
 public function saveAction()
 {
     $plugin_id = waRequest::get('id');
     if (!$plugin_id) {
         throw new waException(_ws("Can't save plugin settings: unknown plugin id"));
     }
     $namespace = $this->getAppId() . '_' . $plugin_id;
     /**
      * @var shopPlugin $plugin
      */
     $plugin = waSystem::getInstance()->getPlugin($plugin_id);
     $settings = (array) $this->getRequest()->post($namespace);
     $files = waRequest::file($namespace);
     $settings_defenitions = $plugin->getSettings();
     foreach ($files as $name => $file) {
         if (isset($settings_defenitions[$name])) {
             $settings[$name] = $file;
         }
     }
     try {
         $response = $plugin->saveSettings($settings);
         $response['message'] = _w('Saved');
         $this->displayJson($response);
     } catch (Exception $e) {
         $this->setError($e->getMessage());
         $this->displayJson(array(), $e->getMessage());
     }
 }
 public function execute()
 {
     $p = $path = rtrim(waRequest::post('path'), ' /');
     $file = waRequest::post('file');
     try {
         if ($file) {
             if (!is_array($file)) {
                 $file = array($file);
             }
             foreach ($file as $f) {
                 $f = $path . '/' . $f;
                 waFiles::delete(wa()->getDataPath($f, true, null, false));
             }
             $this->log('file_delete', count($file));
         } else {
             $path = wa()->getDataPath($path, true, null, false);
             if (!is_writable($path)) {
                 $this->errors = sprintf(_w("Folder could not bet deleted due to the insufficient permissions."), $p);
             } else {
                 waFiles::delete($path);
                 $this->log('file_delete', 1);
             }
         }
     } catch (Exception $e) {
         $this->errors = $e->getMessage();
     }
 }
 public function execute()
 {
     $order_id = waRequest::request('order_id', 0, 'int');
     $id = waRequest::request('id', 0, 'int');
     $to = waRequest::request('to');
     $nm = new shopNotificationModel();
     $n = $nm->getById($id);
     if (!$n) {
         $this->errors = sprintf_wp('%s entry not found', _w('Notification'));
         return;
     }
     $om = new shopOrderModel();
     $o = $om->getById($order_id);
     if (!$o) {
         $this->errors = _w('Order not found');
         return;
     }
     shopHelper::workupOrders($o, true);
     $opm = new shopOrderParamsModel();
     $o['params'] = $opm->get($order_id);
     try {
         $contact = $o['contact_id'] ? new shopCustomer($o['contact_id']) : wa()->getUser();
         $contact->getName();
     } catch (Exception $e) {
         $contact = new shopCustomer(wa()->getUser()->getId());
     }
     $cm = new shopCustomerModel();
     $customer = $cm->getById($contact->getId());
     if (!$customer) {
         $customer = $cm->getEmptyRow();
     }
     $workflow = new shopWorkflow();
     // send notifications
     shopNotifications::sendOne($id, array('order' => $o, 'customer' => $contact, 'status' => $workflow->getStateById($o['state_id'])->getName()), $to);
 }
 public function execute()
 {
     $tag_name = waRequest::get('tag');
     $tag_name = urldecode($tag_name);
     $tag_model = new photosTagModel();
     $tag = $tag_model->getByName($tag_name);
     $title = _w('Tag not found');
     $photos = array();
     $config = $this->getConfig();
     if ($tag) {
         $hash = '/tag/' . $tag_name;
         $collection = new photosCollection($hash);
         $count = $config->getOption('photos_per_page');
         $photos = $collection->getPhotos("*,thumb,thumb_crop,thumb_middle,thumb_big,tags,edit_rights", 0, $count);
         $photos = photosCollection::extendPhotos($photos);
         $title = $collection->getTitle();
         $this->view->assign('frontend_link', photosCollection::getFrontendLink($hash));
         $this->view->assign('total_count', $collection->count());
     }
     $this->view->assign('sidebar_width', $config->getSidebarWidth());
     $this->view->assign('title', $title);
     $this->view->assign('photos', $photos);
     $this->view->assign('big_size', $config->getSize('big'));
     $this->view->assign('sort_method', 'upload_datetime');
     $this->template = 'templates/actions/photo/PhotoList.html';
 }
 public function execute()
 {
     $path = null;
     $photo_rights_model = new photosPhotoRightsModel();
     $photo_id = waRequest::get('photo_id', null, waRequest::TYPE_INT);
     if ($photo_rights_model->checkRights($photo_id, true)) {
         $photo_model = new photosPhotoModel();
         if ($photo = $photo_model->getById($photo_id)) {
             if (waRequest::get('original')) {
                 $path = photosPhoto::getOriginalPhotoPath($photo);
             } else {
                 $path = photosPhoto::getPhotoPath($photo);
             }
         }
     }
     if ($path) {
         if ($attach = waRequest::get('attach') ? true : false) {
             $response = $this->getResponse();
             $response->addHeader('Expires', 'tomorrow');
             $response->addHeader('Cache-Control', ($photo['status'] == 1 ? 'public' : 'private') . ', max-age=' . 86400 * 30);
         }
         waFiles::readFile($path, $attach ? null : basename($photo['name'] . '.' . $photo['ext']), true, !$attach);
     } else {
         throw new waException(_w("Photo not found"), 404);
     }
 }
 public function execute()
 {
     if (!isset($this->blocks['title']) || strlen($this->blocks['title']) <= 0) {
         $this->setTitle(_w('Checklists'));
     }
     $this->executeAction('sidebar', new checklistsBackendSidebarAction());
 }
 public function execute()
 {
     $this->getResponse()->addHeader('Content-type', 'application/json');
     if ($comment_id = $this->getRequest()->post('id', 0, waRequest::TYPE_INT)) {
         $comment_model = new blogCommentModel();
         $comment = $comment_model->getById($comment_id);
         if (!$comment) {
             throw new waException(_w('Comment not found'), 404);
         }
         $post_model = new blogPostModel();
         if (!($post = $post_model->getBlogPost(array('id' => $comment['post_id'], 'blog_id' => $comment['blog_id'])))) {
             throw new waException(_w('Post not found'), 404);
         }
         $user_id = $this->getUser()->getId();
         $rights = blogHelper::checkRights($comment['blog_id'], $user_id, blogRightConfig::RIGHT_READ_WRITE);
         if ($rights == blogRightConfig::RIGHT_READ_WRITE && $user_id != $post['contact_id']) {
             throw new waRightsException(_w('Access denied'), 403);
         }
         $status = $this->getRequest()->post('status', blogCommentModel::STATUS_DELETED);
         if ($status != blogCommentModel::STATUS_DELETED) {
             $status = blogCommentModel::STATUS_PUBLISHED;
         }
         $changed = $comment_model->updateById($comment_id, array('status' => $status));
         $count = $comment_model->getCount($comment['blog_id'], $comment['post_id']);
         if ($changed) {
             if ($status == blogCommentModel::STATUS_DELETED) {
                 $this->log('comment_delete', 1);
             } else {
                 $this->log('comment_restore', 1);
             }
         }
         $this->response = array('count_str' => $count . " " . _w('comment', 'comments', $count), 'status' => $status, 'changed' => $changed);
     }
 }
 protected function init()
 {
     parent::init();
     $this->setMessage(self::ERROR_REQUIRED, _w('%subject% URL must not be empty'));
     $this->setMessage(self::ERROR_URL_IN_USE, _w('%subject% URL is in use. Please enter another URL'));
     $this->setMessage(self::ERROR_INVALID, _w('%subject% URL is invalid'));
 }
 public function execute()
 {
     $service_model = new shopServiceModel();
     $service_product_model = new shopProductServicesModel();
     $id = waRequest::get('id', null, waRequest::TYPE_INT);
     $edit = waRequest::get('edit', null, waRequest::TYPE_STRING_TRIM);
     if ($edit == 'name') {
         $service_model->updateById($id, array('name' => waRequest::post('name', '', waRequest::TYPE_STRING_TRIM)));
         return;
     }
     if ($id) {
         $service = $service_model->getById($id);
         if (!$service) {
             $this->errors[] = _w("Unknown service to update");
             return;
         }
     }
     if ($id) {
         // delete products
         $delete_products = waRequest::post('delete_product', array(), waRequest::TYPE_ARRAY_INT);
         $service_product_model->deleteByProducts($delete_products, $id);
     }
     $id = $service_model->save($this->getData(), $id, true);
     $this->response = array('id' => $id);
 }
 public function execute()
 {
     $filter = array();
     $filter['enabled'] = true;
     $filter['extras'] = 'themes';
     $options = array('installed' => true);
     $applications = installerHelper::getInstaller()->getApps($options, $filter);
     $search = array();
     $search['slug'] = waRequest::get('slug');
     $search['vendor'] = waRequest::get('vendor', 'webasyst');
     $search['vendor'] = waRequest::get('theme_vendor', 'webasyst');
     if (!empty($search['slug'])) {
         $options = array('action' => true, 'requirements' => true, 'inherited' => array_keys($applications));
         if ($theme = installerHelper::getInstaller()->getItemInfo('*/themes/' . $search['slug'], $options)) {
             $theme['app'] = preg_replace('@/.+$@', '', $theme['slug']);
         }
         $this->view->assign('identity_hash', installerHelper::getHash());
         $this->view->assign('promo_id', installerHelper::getPromoId());
         $this->view->assign('domain', installerHelper::getDomain());
         $this->view->assign('theme', $theme);
         $this->view->assign('query', waRequest::get('query', '', waRequest::TYPE_STRING_TRIM) . '/');
     } else {
         throw new waException(_w('Theme not found'), 404);
     }
 }
 public function execute()
 {
     $query = trim(waRequest::post('q'), ' /');
     $hash = '/search/' . $query;
     $collection = new photosCollection($hash);
     if ($query == 'rate>0') {
         $collection->orderBy('p.rate DESC, p.id');
     }
     $this->template = 'templates/actions/photo/PhotoList.html';
     $count = $this->getConfig()->getOption('photos_per_page');
     $photos = $collection->getPhotos("*,thumb,thumb_crop,thumb_middle,thumb_big,tags,edit_rights", 0, $count);
     $photos = photosCollection::extendPhotos($photos);
     $frontend_link = $query == 'rate>0' ? photosCollection::getFrontendLink('favorites', false) : photosCollection::getFrontendLink($hash, false);
     /**
      * @event search_frontend_link
      * @param string $query
      * @return array of bool|string if false - default frontend_link isn't overridden, if string - override default frontend link
      */
     $res = wa()->event('search_frontend_link', $query);
     foreach ($res as $r) {
         if (is_string($r)) {
             $frontend_link = $r;
             break;
         }
     }
     $config = $this->getConfig();
     $this->view->assign('sidebar_width', $config->getSidebarWidth());
     $this->view->assign('big_size', $config->getSize('big'));
     $this->view->assign('frontend_link', $frontend_link);
     $this->view->assign('photos', $photos);
     $this->view->assign('title', $query == 'rate>0' ? _w('Rated') : $collection->getTitle());
     $this->view->assign('total_count', $collection->count());
     $this->view->assign('sort_method', $query == 'rate>0' ? 'rate' : 'upload_datetime');
     $this->view->assign('hash', $hash);
 }
 public function execute()
 {
     $plugin_id = waRequest::get('id', null);
     $plugins_count = 0;
     if ($plugin_id) {
         $plugins = $this->getConfig()->getPlugins();
         $plugins_count = count($plugins);
         if (isset($plugins[$plugin_id])) {
             /**
              * @var photosPlugin $plugin
              */
             $plugin = waSystem::getInstance()->getPlugin($plugin_id);
             waSystem::pushActivePlugin($plugin_id, 'photos');
             $namespace = 'photos_' . $plugin_id;
             $params = array();
             $params['id'] = $plugin_id;
             $params['namespace'] = $namespace;
             $params['title_wrapper'] = '%s';
             $params['description_wrapper'] = '<br><span class="hint">%s</span>';
             $params['control_wrapper'] = '<div class="name">%s</div><div class="value">%s %s</div>';
             $settings_controls = $plugin->getControls($params);
             $this->getResponse()->setTitle(_w(sprintf('Plugin %s settings', $plugin->getName())));
             $this->view->assign('plugin_info', $plugins[$plugin_id]);
             $this->view->assign('plugin_id', $plugin_id);
             $this->view->assign('settings_controls', $settings_controls);
             waSystem::popActivePlugin();
         }
     }
     $this->view->assign('plugins_count', $plugins_count);
 }
 public function execute()
 {
     $extended = false;
     $this->view->assign('action', 'update');
     $update_counter = 0;
     $messages = installerMessage::getInstance()->handle(waRequest::get('msg'));
     $this->view->assign('error', false);
     $app = null;
     try {
         $app_list = installerHelper::getApps($messages, $update_counter);
         $slug = waRequest::get('slug');
         $vendor = waRequest::get('vendor');
         $edition = waRequest::get('edition');
         foreach ($app_list as $info) {
             if ($info['slug'] == $slug && $info['vendor'] == $vendor && $info['edition'] == $edition) {
                 $app = $info;
                 break;
             }
         }
         if (!$app) {
             throw new waException(_w('Application not found'));
         }
     } catch (Exception $ex) {
         $msg = installerMessage::getInstance()->raiseMessage($ex->getMessage(), installerMessage::R_FAIL);
         $this->redirect(array('module' => 'apps', 'msg' => $msg));
     }
     $this->view->assign('identity_hash', installerHelper::getHash());
     $this->view->assign('messages', $messages);
     $this->view->assign('update_counter', $update_counter);
     $this->view->assign('app', $app);
     $this->view->assign('title', sprintf(_w('Application "%s"'), $app['name']));
 }
Beispiel #28
0
 public function move($id, $after_id, $context = null)
 {
     $entry = $this->getById($id);
     if (!$entry) {
         throw new waException(sprintf(_w("%s entry not found"), $this->table) . var_export($id, true) . __LINE__);
     }
     if (!empty($after_id)) {
         $after_item = $this->getById($after_id);
         if (!$after_item) {
             throw new waException(sprintf(_w("%s entry not found"), $this->table) . var_export($after_id, true) . __LINE__);
         }
         $sort = $after_item[$this->sort];
     } else {
         $sort = -1;
     }
     $sql = null;
     if ($sort > $entry['sort']) {
         $sql = "UPDATE {$this->table} SET {$this->sort} = {$this->sort} - 1 WHERE {$this->sort} > i:sort_old AND {$this->sort} <= i:sort";
     } elseif ($sort < $entry['sort']) {
         $sort++;
         $sql = "UPDATE {$this->table} SET {$this->sort} = {$this->sort} + 1 WHERE {$this->sort} >= i:sort AND {$this->sort} < i:sort_old";
     }
     if ($sql) {
         $params = array('sort' => $sort, 'sort_old' => $entry[$this->sort]);
         if ($context !== null) {
             $sql .= ' AND ' . $this->getWhereByField($this->context, $context);
         }
         $this->exec($sql, $params);
         $this->updateById($id, array($this->sort => (int) $sort));
     }
     return $sort;
 }
 public function execute()
 {
     $photo_id = waRequest::get('photo_id', null, waRequest::TYPE_INT);
     $size = waRequest::get('size', null, waRequest::TYPE_STRING);
     $album = null;
     $photo_model = new photosPhotoModel();
     $photo = $photo_model->getById($photo_id);
     if (!$photo) {
         throw new waException(_w("Unknown photo"));
     }
     $photo['frontend_link'] = photosFrontendPhoto::getLink($photo, $album);
     $sizes = $this->getConfig()->getSizes();
     $contexts = array();
     foreach ($sizes as $sz) {
         $contexts[$sz]['html'] = photosPhoto::getEmbedImgHtml($photo, $sz);
         $contexts[$sz]['url'] = photosPhoto::getPhotoUrl($photo, $sz, true);
     }
     if (!$size || !isset($contexts[$size])) {
         $size = $sizes[0];
     }
     $domains = photosPhoto::getDomains(null, $photo);
     if (count($domains) <= 1) {
         $domains = array();
     }
     $this->view->assign('photo', $photo);
     $this->view->assign('sizes', $sizes);
     $this->view->assign('size', $size);
     $this->view->assign('contexts', $contexts);
     $this->view->assign('original_domain', wa()->getRootUrl(true));
     $this->view->assign('domains', $domains);
 }
 public function execute()
 {
     // only allowed to global admin
     if (!wa()->getUser()->getRights('webasyst', 'backend')) {
         throw new waRightsException(_w('Access denied'));
     }
     $contacts = $this->getRequest()->post('contacts', array(), 'array_int');
     $groups = $this->getRequest()->post('groups', array(), 'array_int');
     if (!$contacts || !$groups) {
         return;
     }
     $ugm = new waUserGroupsModel();
     $gm = new waGroupModel();
     foreach ($contacts as $id) {
         if ($groups) {
             $ugm->delete($id, $groups);
         }
     }
     $counters = array();
     foreach ($groups as $gid) {
         $cnt = $ugm->countByField(array('group_id' => $gid));
         $gm->updateCount($gid, $cnt);
         $counters[$gid] = $cnt;
     }
     $contacts_count = count($contacts);
     $groups_count = count($groups);
     $this->response['message'] = sprintf(_w("%d user excluded", "%d users excluded", $contacts_count), $contacts_count);
     $this->response['message'] .= ' ';
     $this->response['message'] .= sprintf(_w("from %d group", "from %d groups", $groups_count), $groups_count);
     $this->response['counters'] = $counters;
 }