function finishTaskAction($taskId = 0) { $task = Tasks\Task::get((int) $taskId); $result = new Server\Result(); if ($task) { if ($task->resp_user_id != \Users\User::$cur->id) { $result->content = 'Вы не работаете над этой задачей'; } else { if ($task->task_status_id == 2) { $task->task_status_id = 3; $task->date_end = date('Y-m-d H:i:s'); if (!empty($_GET['results'])) { $task->results = htmlspecialchars($_GET['results']); } $task->save(); $result->successMsg = 'Задача выполнена!'; $result->send(); } elseif ($task->task_status_id == 3) { $result->content = 'Задача уже завершена'; } elseif ($task->task_status_id == 1) { $result->content = 'Задача еще ни кем не выполняется'; } } } else { $result->content = 'Задача не найдена'; } $result->success = false; $result->send(); }
public function closeCartAction($cartId = 0) { $cart = Ecommerce\Cart::get((int) $cartId); $result = new Server\Result(); if ($cart && $cart->cart_status_id != 5) { $cart->cart_status_id = 5; $cart->save(); $result->successMsg = 'Заказ был завершен'; $result->send(); } $result->success = false; $result->content = 'Такая корзина не найдена'; $result->send(); }
public function completeTransferAction($transferId) { $transfer = Money\Transfer::get($transferId); $result = new Server\Result(); $result->success = $transfer->complete(); $result->successMsg = 'Перевод был завершен'; $result->content = 'Не удалось завершить перевод'; $result->send(); }
public function formPopUpAction() { if (strpos($_GET['item'], ':')) { $raw = explode(':', $_GET['item']); $modelName = $raw[0]; $id = $raw[1]; $model = $modelName::get($id, $modelName::index(), !empty($_GET['params']['dataManagerParams']) ? $_GET['params']['dataManagerParams'] : []); } else { $modelName = $_GET['item']; $model = new $modelName(); } $params = []; if (!empty($_GET['params'])) { $params = $_GET['params']; if (!empty($params['preset'])) { $model->setParams($params['preset']); } } if (!empty($_GET['params']['dataManagerParams']['appType'])) { $params['appType'] = $_GET['params']['dataManagerParams']['appType']; } $formName = !empty($_GET['formName']) ? $_GET['formName'] : (!empty($_GET['params']['formName']) ? $_GET['params']['formName'] : 'manager'); $form = new Ui\ActiveForm($model, $formName); if (!empty($_GET['_']) || !empty($_POST['_'])) { $return = new Server\Result(); ob_start(); $form->checkRequest($params, true); $_GET['item'] = get_class($form->model) . ($model->pk() ? ':' . $model->pk() : ''); $get = $_GET; if (isset($get['notSave'])) { unset($get['notSave']); } $form->action = (App::$cur->system ? '/' . App::$cur->name : '') . '/ui/formPopUp/?' . http_build_query($get); $form->draw($params, true); $return->content = ob_get_contents(); ob_end_clean(); $return->send(); } else { $form->checkRequest($params); $_GET['item'] = get_class($form->model) . ($model->pk() ? ':' . $model->pk() : ''); $get = $_GET; if (isset($get['notSave'])) { unset($get['notSave']); } $form->action = (App::$cur->system ? '/' . App::$cur->name : '') . '/ui/formPopUp/?' . http_build_query($get); $this->view->setTitle(($model && $model->pk() ? 'Изменить ' : 'Создать ') . $form->header); $this->view->page(['content' => 'form', 'data' => compact('form', 'params')]); } }
function editFileAction($templateName) { $template = \View\Template::get($templateName, \App::$primary); if (!empty($_GET['path']) && file_exists($template->path . '/' . Tools::parsePath($_GET['path']))) { $code = file_get_contents("php://input"); if (!empty($code)) { $result = new Server\Result(); $result->successMsg = 'Файл сохранен'; $content = file_put_contents($template->path . '/' . Tools::parsePath($_GET['path']), $code); $result->send(); } $content = file_get_contents($template->path . '/' . Tools::parsePath($_GET['path'])); $this->libs->loadLib('Ace'); $this->view->page(['content' => 'Template/edit', 'data' => compact('template', 'content')]); } else { $this->view->page(['content' => 'Template/chooseFile', 'data' => compact('template')]); } }
public function subscribe($chanelAlias) { $chanel = $this->getChanel($chanelAlias); $subscriber = $this->getCurSubscriber(); $subscribe = Notifications\Subscribe::get([['subscriber_id', $subscriber->id], ['chanel_id', $chanel->id]]); if ($subscribe) { $response = new Server\Result(); $response->successMsg = 'Вы уже подписаны'; $response->send(); } $subscribe = new Notifications\Subscribe(); $subscribe->subscriber_id = $subscriber->id; $subscribe->chanel_id = $chanel->id; $subscribe->save(); $response = new Server\Result(); $response->successMsg = 'Вы были подписаны на уведомления'; $response->send(); }
public function checkAction() { $result = new Server\Result(); $device = $this->Notifications->getCurDevice(); $subscriber = $this->Notifications->getCurSubscriber(); $subscribes = Notifications\Subscribe::getList(['where' => ['subscriber_id', $subscriber->id]]); $chanelsIds = []; foreach ($subscribes as $subscribe) { $chanelsIds[$subscribe->chanel_id] = $subscribe->chanel_id; } $result->content = []; if ($chanelsIds) { $notifications = Notifications\Notification::getList(['where' => [['date_create', $device->date_last_check, '>='], ['chanel_id', implode(',', $chanelsIds), 'IN']]]); foreach ($notifications as $notification) { $result->content[] = $notification->_params; } } $device->date_last_check = date('Y-m-d H:i:s'); $device->save(); $result->send(); }
public function searchAction() { $result = new Server\Result(); $searchString = filter_input(INPUT_GET, 'search', FILTER_SANITIZE_STRING); $searchString = trim(preg_replace('![^A-zА-я0-9@-_\\. ]!iSu', ' ', urldecode($searchString))); if (!$searchString) { $result->content = []; $result->send(); } try { $modelName = trim(filter_input(INPUT_GET, 'modelName', FILTER_SANITIZE_STRING)); if (!$modelName) { throw new Exception('Не указана модель'); } $model = new $modelName(); if (!$model || !is_subclass_of($model, 'Model')) { throw new Exception('Модель не найдена'); } $formName = trim(filter_input(INPUT_GET, 'formName', FILTER_SANITIZE_STRING)); if (!$formName) { throw new Exception('Не указано название формы'); } if (empty($modelName::$forms[$formName])) { throw new Exception('Не существует указанной формы'); } $activeForm = new Ui\ActiveForm($model, $formName); $inputs = $activeForm->getInputs(); $inputName = trim(filter_input(INPUT_GET, 'inputName', FILTER_SANITIZE_STRING)); if (empty($inputs[$inputName])) { throw new Exception('У формы нет такого поля'); } } catch (Exception $exc) { $result->success = false; $result->content = $exc->getMessage(); $result->send(); } $options = ['where' => []]; $searchArr = []; foreach (explode(' ', $searchString) as $part) { $colWhere = []; $first = true; foreach ($inputs[$inputName]['cols'] as $col) { $part = trim($part); if ($part && strlen($part) > 2) { $colWhere[] = [$col, '%' . $part . '%', 'LIKE', $first ? 'AND' : 'OR']; $first = false; } } if ($colWhere) { $searchArr[] = $colWhere; } } if ($searchArr) { $options['where'][] = $searchArr; } else { $result->content = []; $result->send(); } $list = $activeForm->getOptionsList($inputs[$inputName], ['noEmptyValue' => true], $modelName, 'aditional', $options); $result->content = $list; $result->send(); }
public function delCategoryAction() { $request = $this->parseRequest(); $dataManager = new Ui\DataManager($request['modelName'], $request['managerName']); if ($dataManager->checkAccess() && !empty($dataManager->managerOptions['categorys'])) { $categoryModel = $dataManager->managerOptions['categorys']['model']; $model = $categoryModel::get($request['key'], $categoryModel::index(), $request['params']); if ($model) { $model->delete($request['params']); } } $result = new Server\Result(); $result->send(); }
public function getPartnerInfoAction($userId = 0) { $userId = (int) $userId; $result = new \Server\Result(); if (!$userId) { $result->success = FALSE; $result->content = 'Не указан пользователь'; $result->send(); } $partners = App::$cur->users->getUserPartners(Users\User::$cur, 8); if (empty($partners['users'][$userId])) { $result->success = FALSE; $result->content = 'Этот пользователь не находится в вашей структуре'; $result->send(); } $user = $partners['users'][$userId]; ob_start(); echo "id:{$user->id}<br />"; echo "E-mail: <a href='mailto:{$user->mail}'>{$user->mail}</a>"; $rewards = Money\Reward::getList(['where' => ['active', 1]]); $levelTypes = ['procent' => 'Процент', 'amount' => 'Сумма']; $itemTypes = ['event' => 'Событие']; foreach ($rewards as $reward) { foreach ($reward->conditions as $condition) { $complete = $condition->checkComplete($userId); ?> <h5 class="<?php echo $complete ? 'text-success' : 'text-danger'; ?> "><?php echo $condition->name(); ?> </h5> <ul> <?php foreach ($condition->items as $item) { $itemComplete = $item->checkComplete($userId); switch ($item->type) { case 'event': $name = \Events\Event::get($item->value, 'event')->name(); break; } ?> <li> <b class="<?php echo $itemComplete ? 'text-success' : 'text-danger'; ?> "><?php echo $name; ?> <?php echo $item->recivedCount($userId); ?> </b>/<?php echo $item->count; ?> <br /> </li> <?php } ?> </ul> <?php } } $result->content = ob_get_contents(); ob_end_clean(); $result->send(); }
public function getcartAction() { $result = new Server\Result(); ob_start(); $this->view->widget('Ecommerce\\cart'); $result->content = ob_get_contents(); ob_end_clean(); $result->send(); }
public function sendFormAction($chatId = 0) { $chatId = (int) $chatId; $result = new Server\Result(); if (!$chatId || !($chat = \Chats\Chat::get($chatId))) { $result->success = false; $result->content = 'Такого чата не существует'; $result->send(); } if (!Users\User::$cur->id) { $result->success = false; $result->content = 'Вы не авторизованы'; $result->send(); } if (empty($_POST['chat-message']) || !trim($_POST['chat-message'])) { $result->success = false; $result->content = 'Сообщение не может быть пустым'; $result->send(); } if (Chats\Chat\Ban::get(['user_id', \Users\User::$cur->id])) { $result->success = false; $result->content = 'Вы не можете писать в чат'; $result->send(); } $message = new \Chats\Chat\Message(); $message->user_id = Users\User::$cur->id; $message->chat_id = $chatId; $message->text = htmlspecialchars(trim($_POST['chat-message'])); $message->save(); $result->successMsg = 'Ваше сообщение было отправлено'; $result->send(); }