public function backendOrder()
 {
     if (waRequest::get('hash')) {
         return array('info_section' => wa()->getView()->fetch($this->path . '/templates/actions/backend/BackendOrder.html'));
     }
     return null;
 }
 protected function getId()
 {
     if (!empty($this->params['limited_own_profile'])) {
         return wa()->getUser()->getId();
     }
     return (int) waRequest::get('id');
 }
 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']));
 }
 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()
 {
     $this->setLayout(new shopBackendLayout());
     $status = waRequest::get('status');
     $tab = waRequest::get('tab');
     $model = new waModel();
     $cities = $model->query("SELECT * FROM shop_deliveryshop_city ORDER BY city ASC")->fetchAll();
     $city['data'] = $cities;
     $city['new'] = $model->query("SELECT COUNT(*) FROM shop_deliveryshop_city WHERE status='new'")->fetchField();
     $city['completed'] = $model->query("SELECT COUNT(*) FROM shop_deliveryshop_city WHERE status='completed'")->fetchField();
     $city['flag-white'] = $model->query("SELECT COUNT(*) FROM shop_deliveryshop_city WHERE status='flag-white'")->fetchField();
     $city['refunded'] = $model->query("SELECT COUNT(*) FROM shop_deliveryshop_city WHERE status='refunded'")->fetchField();
     $city['all'] = $model->query("SELECT COUNT(*) FROM shop_deliveryshop_city")->fetchField();
     foreach ($city['data'] as $key => &$c) {
         if (is_numeric($c['region'])) {
             $c['region'] = $model->query("SELECT name FROM wa_region WHERE code='" . $c['region'] . "' AND country_iso3='rus'")->fetchField();
         }
         if ($status && $status != $c['status'] && $tab == 'shop') {
             unset($city['data'][$key]);
         }
     }
     $pvz['data'] = $model->query("SELECT * FROM shop_deliveryshop_pvz ORDER BY city ASC")->fetchAll();
     $pvz['new'] = $model->query("SELECT COUNT(*) FROM shop_deliveryshop_pvz WHERE status='new'")->fetchField();
     $pvz['completed'] = $model->query("SELECT COUNT(*) FROM shop_deliveryshop_pvz WHERE status='completed'")->fetchField();
     $pvz['flag-white'] = $model->query("SELECT COUNT(*) FROM shop_deliveryshop_pvz WHERE status='flag-white'")->fetchField();
     $pvz['refunded'] = $model->query("SELECT COUNT(*) FROM shop_deliveryshop_pvz WHERE status='refunded'")->fetchField();
     $pvz['all'] = $model->query("SELECT COUNT(*) FROM shop_deliveryshop_pvz")->fetchField();
     $this->view->assign('cities', $city);
     $this->view->assign('pvz', $pvz);
 }
 public function execute()
 {
     // only allowed to global admin
     if (!wa()->getUser()->getRights('webasyst', 'backend')) {
         throw new waRightsException('Access denied.');
     }
     $collection = new contactsCollection('users/all');
     $group = null;
     $memberIds = array();
     if ($id = waRequest::get('id')) {
         $group_model = new waGroupModel();
         $group = $group_model->getById($id);
     }
     if ($group) {
         $user_groups_model = new waUserGroupsModel();
         $memberIds = $user_groups_model->getContactIds($id);
     }
     $users = $collection->getContacts('id,name');
     // array(id => array(id=>...,name=>...))
     $members = array();
     foreach ($memberIds as $mid) {
         if (isset($users[$mid])) {
             $members[$mid] = $users[$mid];
             unset($users[$mid]);
         }
     }
     usort($members, array($this, '_cmp'));
     usort($users, array($this, '_cmp'));
     $this->view->assign('group', $group);
     $this->view->assign('notIncluded', $users);
     $this->view->assign('members', $members);
 }
 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()
 {
     $plugin_id = waRequest::get('id');
     if (!$plugin_id) {
         throw new waException(_ws("Can't save plugin settings: unknown plugin id"));
     }
     $namespace = 'photos_' . $plugin_id;
     /**
      * @var photosPlugin $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 {
         $plugin->saveSettings($settings);
     } catch (Exception $e) {
         $this->errors = $e->getMessage();
     }
 }
 public function execute()
 {
     $app_id = waRequest::get('app_id');
     $app = wa()->getAppInfo($app_id);
     $this->view->assign('items', $this->getItems($app_id));
     $this->view->assign('app', $app);
     $domain = siteHelper::getDomain();
     $routes = wa()->getRouting()->getByApp($app_id, $domain);
     if ($routes) {
         $event_params = array('app_id' => $app_id, 'routes' => $routes);
         $result = wa($app_id)->event(array($app_id, 'personal.settings'), $event_params);
         if (!empty($result[$app_id])) {
             $this->view->assign('personal_settings', $result[$app_id]);
         }
         $domain = siteHelper::getDomain();
         $domain_config_path = $this->getConfig()->getConfigPath('domains/' . $domain . '.php');
         if (file_exists($domain_config_path)) {
             $domain_config = (include $domain_config_path);
         } else {
             $domain_config = array();
         }
     }
     $this->view->assign('domain_url', 'http://' . $domain);
     $this->view->assign('settled', $routes ? true : false);
     $this->view->assign('enabled', !isset($domain_config['personal'][$app_id]) || $domain_config['personal'][$app_id]);
     $this->template = wa()->getAppPath($this->getTemplate(), 'site');
 }
 public function dispatch()
 {
     if ($this->system->getEnv() == 'frontend') {
         $module = 'frontend';
     } else {
         $module = waRequest::get($this->options['module'], $this->system->getEnv());
     }
     $module = waRequest::param('module', $module);
     $action = waRequest::param('action', waRequest::get($this->options['action']));
     $plugin = waRequest::param('plugin', waRequest::get('plugin', ''));
     // event init
     if (!waRequest::request('background_process')) {
         if (method_exists($this->system->getConfig(), 'onInit')) {
             $this->system->getConfig()->onInit();
         }
     }
     if ($widget = waRequest::param('widget')) {
         $this->executeWidget($widget, $action);
     } elseif ($this->system->getEnv() == 'backend') {
         $url = explode("/", $this->system->getConfig()->getRequestUrl(true));
         if (isset($url[2]) && isset($url[3]) && $url[2] == 'widgets') {
             $this->executeWidget($url[3], $action);
         } else {
             $this->execute($plugin, $module, $action);
         }
     } else {
         $this->execute($plugin, $module, $action);
     }
 }
 public function execute()
 {
     $hash = $this->get('hash');
     $collection = new shopProductsCollection($hash);
     $offset = waRequest::get('offset', 0, 'int');
     if ($offset < 0) {
         throw new waAPIException('invalid_param', 'Param offset must be greater than or equal to zero');
     }
     $limit = waRequest::get('limit', 100, 'int');
     if ($limit < 0) {
         throw new waAPIException('invalid_param', 'Param limit must be greater than or equal to zero');
     }
     if ($limit > 1000) {
         throw new waAPIException('invalid_param', 'Param limit must be less or equal 1000');
     }
     $this->response['count'] = $collection->count();
     $this->response['offset'] = $offset;
     $this->response['limit'] = $limit;
     $this->response['products'] = array_values($collection->getProducts('*', $offset, $limit));
     $image_size = wa('shop')->getConfig()->getImageSize('thumb');
     foreach ($this->response['products'] as &$p) {
         if ($p['image_id']) {
             $p['image_url'] = shopImage::getUrl(array('id' => $p['image_id'], 'product_id' => $p['id'], 'ext' => $p['ext']), $image_size, true);
         }
     }
     unset($p);
 }
 public function execute()
 {
     $type = waRequest::get('type', '', waRequest::TYPE_STRING_TRIM);
     $parent_id = waRequest::get('parent_id', 0, waRequest::TYPE_INT);
     if ($parent_id) {
         $category_model = new shopCategoryModel();
         $parent = $category_model->getById($parent_id);
     }
     $this->template = 'DialogProduct' . ucfirst($type) . 'Create';
     $this->view->assign(array('type' => $type, 'parent' => $parent_id ? $parent : array()));
     if ($type == 'category') {
         $tag_model = new shopTagModel();
         $stuff = '%category_url%';
         $frontend_url = wa()->getRouteUrl('/frontend/category', array('category_url' => $stuff), true);
         $pos = strrpos($frontend_url, $stuff);
         $fontend_base_url = $pos !== false ? rtrim(substr($frontend_url, 0, $pos), '/') . '/' : $frontend_url;
         $feature_model = new shopFeatureModel();
         $features = $feature_model->getFeatures('selectable', 1);
         $features += $feature_model->getFeatures('type', 'boolean');
         $features = $feature_model->getValues($features);
         $this->view->assign(array('cloud' => $tag_model->getCloud(), 'currency' => wa()->getConfig()->getCurrency(), 'frontend_base_url' => $fontend_base_url, 'lang' => substr(wa()->getLocale(), 0, 2), 'features' => $features));
     } else {
         if ($type == 'set') {
             $this->view->assign('default_count', $this->set_dynamic_default_count);
         }
     }
 }
 public function execute()
 {
     $product_id = (int) waRequest::get('id');
     $product = new shopProduct($product_id);
     $type_model = new shopTypeModel();
     $type = $type_model->getById($product['type_id']);
     if ($product['cross_selling'] === null) {
         $product['cross_selling'] = $type['cross_selling'] ? 1 : 0;
     }
     if ($product['upselling'] === null) {
         $product['upselling'] = $type['upselling'];
     }
     // if manually
     if ($product['cross_selling'] == 2 || $product['upselling'] == 2) {
         $related_model = new shopProductRelatedModel();
         $related = $related_model->getAllRelated($product_id);
     } else {
         $related = array();
     }
     if ($type['upselling']) {
         $type_upselling_model = new shopTypeUpsellingModel();
         $data = $type_upselling_model->getByType($type['id']);
         $type['upselling_html'] = shopSettingsRecommendationsAction::getConditionHTML($data);
     }
     if ($type['cross_selling'] && substr($type['cross_selling'], 0, 9) == 'category/') {
         $category_model = new shopCategoryModel();
         $type['category'] = $category_model->getById(substr($type['cross_selling'], 9));
     }
     $this->view->assign(array('type' => $type, 'product' => $product, 'related' => $related));
 }
 public function execute()
 {
     $messages = installerMessage::getInstance()->handle(waRequest::get('msg'));
     installerHelper::checkUpdates($messages);
     if ($m = $this->view->getVars('messages')) {
         $messages = array_merge($m, $messages);
     }
     $this->view->assign('messages', $messages);
     $plugins = 'wa-plugins/payment';
     $apps = wa()->getApps();
     if (isset($apps['shop'])) {
         $plugins = 'shop';
     } else {
         ksort($apps);
         foreach ($apps as $app => $info) {
             if (!empty($info['plugins'])) {
                 $plugins = $app;
                 break;
             }
         }
     }
     $model = new waAppSettingsModel();
     $this->view->assign('update_counter', $model->get($this->getApp(), 'update_counter'));
     $this->view->assign('module', waRequest::get('module', 'backend'));
     $this->view->assign('default_query', array('plugins' => $plugins));
 }
 public function execute()
 {
     $parent_id = waRequest::get('parent_id');
     $category_model = new shopCategoryModel();
     $cats = $category_model->getTree($parent_id, waRequest::get('depth', null, 'int'));
     $stack = array();
     $result = array();
     foreach ($cats as $c) {
         $c['categories'] = array();
         // Number of stack items
         $l = count($stack);
         // Check if we're dealing with different levels
         while ($l > 0 && $stack[$l - 1]['depth'] >= $c['depth']) {
             array_pop($stack);
             $l--;
         }
         // Stack is empty (we are inspecting the root)
         if ($l == 0) {
             // Assigning the root node
             $i = count($result);
             $result[$i] = $c;
             $stack[] =& $result[$i];
         } else {
             // Add node to parent
             $i = count($stack[$l - 1]['categories']);
             $stack[$l - 1]['categories'][$i] = $c;
             $stack[] =& $stack[$l - 1]['categories'][$i];
         }
     }
     $this->response = $result;
     $this->response['_element'] = 'category';
 }
 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 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()
 {
     if (wa()->getUser()->getRights('wacab', 'backend') >= 2) {
         $apps_model = new wacabAppsModel();
         $app = waRequest::get('apps');
         if ($app['parent'] === 'null') {
             $app['parent'] = null;
         }
         if (isset($app['id']) && $app['id'] > 0) {
             $old = $apps_model->getById($app['id']);
             if ($old['app_id'] != $app['app_id'] && $app['type'] == 'app') {
                 $apps_model->exec('UPDATE wacab_apps SET app_id = s:app_id WHERE app_id = s:old_app_id', array('app_id' => $app['app_id'], 'old_app_id' => $old['app_id']));
             }
             $apps_model->updateById($app['id'], $app);
         } else {
             unset($app['id']);
             $app['name'] = json_encode(array($app['name']));
             $apps_model->insert($app);
         }
         $view = self::getView();
         $apps = $apps_model->getAll();
         $types = $apps_model->getTypes();
         $parents = $apps_model->getParents();
         $view->assign('parents', $parents);
         $view->assign('types', $types);
         $view->assign('apps', $apps);
         $view->assign('edit', 0);
         $view->assign('app', array());
         $this->response = array('apps' => $view->fetch(wacabHelper::getAppPath() . '/templates/actions/apps/apps_table.html'), 'form' => $view->fetch(wacabHelper::getAppPath() . '/templates/actions/apps/apps_form.html'));
     } else {
         $this->setError(_wp('No permission to add the app'));
     }
 }
 public function execute()
 {
     $lazy = !is_null(waRequest::get('lazy'));
     if (!$lazy) {
         $this->setLayout(new photosDefaultFrontendLayout());
     } else {
         $this->setTemplate('FrontendPhotos');
     }
     $photos_per_page = wa('photos')->getConfig()->getOption('photos_per_page');
     $limit = $photos_per_page;
     $page = 1;
     if ($lazy) {
         $offset = max(0, waRequest::get('offset', 0, waRequest::TYPE_INT));
     } else {
         $page = max(1, waRequest::get('page', 1, waRequest::TYPE_INT));
         $offset = ($page - 1) * $photos_per_page;
     }
     $c = new photosCollection('publicgallery/myphotos');
     $photos = $c->getPhotos('*', $offset, $limit);
     $photos = photosCollection::extendPhotos($photos);
     $v = wa()->getVersion();
     wa('photos')->getResponse()->addJs('js/lazy.load.js?v=' . $v, true);
     wa('photos')->getResponse()->addJs('js/frontend.photos.js?v=' . $v, true);
     $storage = wa()->getStorage();
     $current_auth = $storage->read('auth_user_data');
     $current_auth_source = $current_auth ? $current_auth['source'] : null;
     $this->view->assign('current_auth', $current_auth, true);
     $adapters = wa()->getAuthAdapters();
     $total_count = $c->count();
     $this->view->assign(array('photos' => $photos, 'page' => $page, 'offset' => $offset, 'photos_per_page' => $photos_per_page, 'total_photos_count' => $total_count, 'lazy_load' => $lazy, 'image_upload_url' => wa()->getRouteUrl('photos/frontend/imageUpload'), 'pages_count' => floor($total_count / $photos_per_page) + 1, 'current_auth_source' => $current_auth_source, 'adapters' => $adapters));
 }
 public function execute()
 {
     $filter = array();
     $filter['enabled'] = true;
     $filter['extras'] = 'themes';
     $app = false;
     $messages = array();
     $applications = installerHelper::getApps($messages, $update_counter, $filter);
     $search = array();
     $search['slug'] = $app_id = waRequest::get('slug');
     $search['vendor'] = waRequest::get('vendor', 'webasyst');
     $themes = wa()->getThemes($search['slug']);
     if (array_filter($search, 'strlen') && ($app = installerHelper::search($applications, $search))) {
         foreach ($app['extras']['themes'] as $id => $info) {
             if (!isset($themes[$id])) {
                 $themes[$id] = new waTheme($id, $search['slug'], true);
                 $themes[$id]['name'] = $info['name'];
                 $themes[$id]['description'] = $info['description'];
             }
             if (!empty($info['payware'])) {
                 $themes[$id]['payware'] = $info['payware'];
             }
             if (!empty($info['img'])) {
                 $themes[$id]['cover'] = $info['img'];
             }
         }
         $this->view->assign('themes', $themes);
         $this->view->assign('messages', $messages);
         $this->view->assign('app_id', $app_id);
         $this->view->assign('app', $app);
         $this->view->assign('slug', $search['slug']);
         $this->view->assign('vendor', $search['vendor']);
     }
 }
 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 execute()
 {
     $id = (int) waRequest::get('id');
     if ($id) {
         $this->form = shopHelper::getCustomerForm($id);
     }
 }
 public function execute()
 {
     $hash = $this->get('hash');
     $collection = new photosCollection($hash);
     $offset = waRequest::get('offset', 0, 'int');
     if ($offset < 0) {
         throw new waAPIException('invalid_param', 'Param offset must be greater than or equal to zero');
     }
     $limit = waRequest::get('limit', 100, 'int');
     if ($limit < 0) {
         throw new waAPIException('invalid_param', 'Param limit must be greater than or equal to zero');
     }
     if ($limit > 1000) {
         throw new waAPIException('invalid_param', 'Param limit must be less or equal 1000');
     }
     $photos = $collection->getPhotos('*,thumb', $offset, $limit);
     foreach ($photos as &$p) {
         if (isset($p['thumb']['url'])) {
             $p['image_url'] = $p['thumb']['url'];
             unset($p['thumb']);
         }
     }
     unset($p);
     $this->response['count'] = $collection->count();
     $this->response['offset'] = $offset;
     $this->response['limit'] = $limit;
     $this->response['photos'] = array_values($photos);
 }
 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()
 {
     $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()
 {
     // Only show categories available to current user
     $crm = new contactsRightsModel();
     $cm = new waContactCategoryModel();
     // List of categories user is allowed to add contacts to
     $categories = $cm->getAll('id');
     //        $allowed = $crm->getAllowedCategories();
     //        if ($allowed === true) {
     //            $allowed = $categories;
     //        }
     //        foreach($categories as $id => &$cat) {
     //            if (!isset($allowed[$id]) || $cat['system_id']) {
     //                unset($categories[$id]);
     //            }
     //            $cat = $cat['name'];
     //        }
     //        unset($cat);
     // Set of catorories that are always checked and disabled in list
     $d = waRequest::get('disabled');
     if (!is_array($d)) {
         $d = array($d);
     }
     $this->view->assign('categories', $categories);
     $this->view->assign('disabled', array_fill_keys($d, true));
 }
 public function execute()
 {
     $name = basename(waRequest::get('file', 'export.csv'));
     $profile = waRequest::get('profile', 0, waRequest::TYPE_INT);
     $file = wa()->getTempPath('csv/download/' . $profile . '/' . $name);
     waFiles::readFile($file, $name);
 }
 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()
 {
     $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()
 {
     $path = rtrim(waRequest::post('path'), ' /');
     $path = wa()->getDataPath($path, true);
     if (!file_exists($path)) {
         throw new waException("File not found", 404);
     }
     $dh = opendir($path);
     $names = array();
     while (($f = readdir($dh)) !== false) {
         if ($f !== '.' && $f !== '..' && is_file($path . '/' . $f)) {
             $names[] = $f;
         }
     }
     natcasesort($names);
     $n = count($names);
     $limit = 100;
     $page = waRequest::get('page', 1);
     $names = array_slice($names, ($page - 1) * $limit, 100);
     $files = array();
     foreach ($names as $name) {
         $f = $name;
         $t = filemtime($path . '/' . $f);
         $files[] = array('file' => htmlspecialchars($name), 'type' => $this->getType($f), 'size' => filesize($path . '/' . $f), 'timestamp' => $t, 'datetime' => waDateTime::format('humandatetime', $t));
     }
     closedir($dh);
     $this->response['pages'] = ceil((double) $n / $limit);
     $this->response['files'] = $files;
 }