public function actionChecklist() { $criteria = new CDbCriteria(); $criteria->addCondition('mstTeamUsers1.teamOwner_id = ' . Yii::app()->user->getInfo()); $criteria->addCondition('mstTeamUsers1.status = 1'); $criteria->with = array('mstTeamUsers1'); $checklist_id = Yii::app()->getRequest()->getParam('list'); $modelArray = Users::model()->findAll($criteria); $checklistModel = new Checklist(); $checklistItemModel = new ChecklistItem(); if (Yii::app()->getRequest()->isAjaxRequest && Yii::app()->getRequest()->getIsPostRequest()) { $checklist_item_id = Yii::app()->getRequest()->getParam('checklist_item_id'); $checklist_item_chacke = Yii::app()->getRequest()->getParam('checklist_item_chack'); $checklistItemModel->updateByPk($checklist_item_id, ['active' => (int) $checklist_item_chacke]); ActionClass::json($_POST); } if (Yii::app()->getRequest()->getIsPostRequest()) { $json = ['success' => false]; $checklist = Yii::app()->getRequest()->getParam('checklist'); $checklist_item = Yii::app()->getRequest()->getParam('checklist_item'); //Create checklist if ($checklist && !empty($checklist)) { $checklistModel->name = $checklist; if ($checklistModel->save()) { return $this->redirect('checklist?list=' . $checklistModel->id); } } //Create checklist item if ($checklist_item && !empty($checklist_item)) { if ($checklist_id) { $checklistItemModel->name = $checklist_item; $checklistItemModel->checklist_id = $checklist_id; if ($checklistItemModel->save()) { return $this->redirect($_SERVER['HTTP_REFERER']); } } } return $this->redirect($_SERVER['HTTP_REFERER']); } Yii::app()->clientScript->registerCssFile(Yii::app()->theme->baseUrl . "/css/request-checklist.css"); Yii::app()->clientScript->registerCssFile(Yii::app()->theme->baseUrl . "/css/request-checklist-resp.css"); Yii::app()->clientScript->registerScriptFile(Yii::app()->theme->baseUrl . "/js/request-checklist.js", CClientScript::POS_END); Yii::app()->clientScript->registerScriptFile(Yii::app()->theme->baseUrl . "/js/checklist.js", CClientScript::POS_END); $checklist = $checklistModel->findByPk(Yii::app()->getRequest()->getParam('list')); $this->render('checklist', ['model' => $this->_model, 'checklist' => $checklist, 'modelArray' => $modelArray]); }
<?php //Imports require_once 'session.php'; require_once 'db.php'; require_once 'ChecklistItem.php'; if (!isset($_POST['itemID']) || !is_numeric($_POST['itemID'])) { http_response_code(422); echo 'Invalid item ID'; exit; } if (!isset($_POST['done'])) { http_response_code(422); echo 'Something borked'; exit; } $con = connect_db(); $listItem = new ChecklistItem(); $listItem->id = intval($_POST['itemID']); $listItem->userid = $_SESSION['USER_ID']; $listItem->date = date('Y-m-d'); $listItem->done = $_POST['done'] === 'true'; $listItem->check($con); $con->close(); http_response_code(200);
<?php //Imports require_once 'db.php'; require_once 'ChecklistItem.php'; if (!isset($_POST['itemID']) || !is_numeric($_POST['itemID'])) { http_response_code(422); echo 'Invalid item ID'; exit; } $con = connect_db(); $employee = new ChecklistItem(); $employee->id = intval($_POST['itemID']); $employee->delete($con); $con->close(); http_response_code(200);
<?php //Imports require_once 'db.php'; require_once 'ChecklistItem.php'; if (!isset($_POST['listID']) || !is_numeric($_POST['listID'])) { http_response_code(422); echo 'Invalid list ID'; exit; } if (!isset($_POST['desc']) || $_POST['desc'] == '') { http_response_code(422); echo 'Invalid description'; exit; } $con = connect_db(); $listItem = new ChecklistItem(); $listItem->listid = intval($_POST['listID']); $listItem->desc = $_POST['desc']; $listItem->save($con); $con->close(); http_response_code(200); echo json_encode($listItem);
<?php //Imports require_once 'db.php'; require_once 'Checklist.php'; require_once 'ChecklistItem.php'; if (empty($_POST['name'])) { header("Location: ../addchecklist?e=name"); exit; } $name = $_POST['name']; $descs = explode('|^|', $_POST['itemdescs']); $con = connect_db(); $list = new Checklist(); $list->name = $_POST['name']; $list->save($con); if ($descs[0] != '') { foreach ($descs as $desc) { $listItem = new ChecklistItem(); $listItem->listid = $list->id; $listItem->desc = $desc; $listItem->save($con); } } $con->close(); header('Location: ../checklist?_=' . $list->id);