public function actionChangeBudgetDueStatus() { //Verify all pending budgets with duedates $Budgets = Budgets::model()->findAll(array('condition' => 't.status_id = :status_id AND CURDATE() > t.budget_duedate', 'params' => array(':status_id' => Status::STATUS_PENDING))); // then change status to cancelled foreach ($Budgets as $budget) { $budget->status_id = 2; $budget->save(false); } }
/** * Creates a new model. */ public function actionCreate() { // create Comments Object $model = new Comments(); // if Comments form exist if (isset($_POST['Comments'])) { // set form elements to Comments model attributes $model->attributes = $_POST['Comments']; $module = Modules::model()->find(array('condition' => 't.module_name = :module_name', 'params' => array(':module_name' => $model->module_id))); // set module_id finded to model $model->module_id = $module->module_id; $project = Yii::app()->user->getState('project_selected'); $model->project_id = $project; // validate and save if ($model->save()) { // create an instance of file uploaded $image = CUploadedFile::getInstancesByName('Comment'); // if file upload exist if (count($image > 0)) { // for each file uploaded for ($i = 0; $i < count($image); $i++) { // create an Document object $modeldocs = new Documents(); $modeldocs->image = $image[$i]; if (!$modeldocs->image->getError()) { // name is formed by date(day+month+year+hour+minutes+seconds+dayofyear+microtime()) $this->tmpFileName = str_replace(" ", "", date('dmYHis-z-') . microtime()); // set the extension file uploaded $extension = $modeldocs->image->getExtensionName(); // if no error saving file if ($modeldocs->image->saveAs(self::FOLDERIMAGES . $this->tmpFileName . '.' . $extension)) { $modeldocs->project_id = $project; $modeldocs->document_name = substr($modeldocs->image->getName(), 0, 30); $modeldocs->document_description = $model->comment_text; $modeldocs->document_path = self::FOLDERIMAGES . $this->tmpFileName . '.' . $extension; $modeldocs->document_revision = '1'; $modeldocs->document_uploadDate = date("Y-m-d"); $modeldocs->document_type = $modeldocs->image->getType(); $modeldocs->document_baseRevision = date('dmYHis'); $modeldocs->user_id = Yii::app()->user->id; $modeldocs->comment_id = $model->primaryKey; // save file uploaded as document if ($modeldocs->save()) { Yii::app()->user->setFlash('CommentMessageSuccess', $modeldocs->image->getName() . " " . Yii::t('comments', 'UploadOk')); } else { Yii::app()->user->setFlash('CommentMessage', $modeldocs->getErrors()); } } else { Yii::app()->user->setFlash('CommentMessage', $modeldocs->image->getName() . " " . Yii::t('comments', 'UploadError')); } } else { Yii::app()->user->setFlash('CommentMessage', $modeldocs->image->error . " " . Yii::t('comments', 'UploadCheckErrors')); } } } // save log $attributes = array('log_date' => date("Y-m-d G:i:s"), 'log_activity' => 'CommentPosted', 'log_resourceid' => $model->comment_resourceid, 'log_type' => Logs::LOG_COMMENTED, 'log_commentid' => $model->primaryKey, 'user_id' => Yii::app()->user->id, 'module_id' => $module->module_name, 'project_id' => $project); Logs::model()->saveLog($attributes); // find project managers to sent comment via mail $recipientsList = array(); $ProjectManagers = Projects::model()->findManagersByProject($project); $managersArray = array(); foreach ($ProjectManagers as $manager) { $managersArray['email'] = $manager->user_email; $managersArray['name'] = $manager->CompleteName; array_push($recipientsList, $managersArray); } // find task owners to send comment via mail if ($module->module_name == 'tasks') { $collaborators = Projects::model()->findAllUsersByProject($project); $ColaboratorsArray = array(); foreach ($collaborators as $colaborator) { $ColaboratorsArray['email'] = $colaborator->user_email; $ColaboratorsArray['name'] = $colaborator->CompleteName; // avoid to repeat email address if (!in_array($ColaboratorsArray, $recipientsList)) { array_push($recipientsList, $ColaboratorsArray); } } } // finding resource title switch ($module->module_name) { case "budgets": $resourceModelTitle = Budgets::model()->findByPk($model->comment_resourceid)->budget_title; break; case "invoices": $resourceModelTitle = Invoices::model()->findByPk($model->comment_resourceid)->invoice_number; break; case "expenses": $resourceModelTitle = Expenses::model()->findByPk($model->comment_resourceid)->expense_name; break; case "documents": $resourceModelTitle = Documents::model()->findByPk($model->comment_resourceid)->document_name; break; case "milestones": $resourceModelTitle = Milestones::model()->findByPk($model->comment_resourceid)->milestone_title; break; case "cases": $resourceModelTitle = Cases::model()->findByPk($model->comment_resourceid)->case_name; break; case "tasks": $resourceModelTitle = Tasks::model()->findByPk($model->comment_resourceid)->task_name; break; default: $resourceModelTitle = "{empty}"; break; } // get project information $project = Projects::model()->findByPk($project); // prepare template to send via email $str = $this->renderPartial('//templates/comments/created', array('model' => $model, 'projectName' => $project->project_name, 'userposted' => Yii::app()->user->CompleteName, 'resourceTitle' => $resourceModelTitle, 'moduleName' => Yii::t('modules', $module->module_name), 'applicationName' => Yii::app()->name, 'applicationUrl' => Yii::app()->createAbsoluteUrl($module->module_name . '/view', array('id' => $model->comment_resourceid))), true); Yii::import('application.extensions.phpMailer.yiiPhpMailer'); $mailer = new yiiPhpMailer(); $subject = Yii::t('email', 'CommentPosted') . " - " . $project->project_name . " - " . Yii::t('modules', $module->module_name); $mailer->pushMail($subject, $str, $recipientsList, Emails::PRIORITY_NORMAL); } else { Yii::app()->user->setFlash('CommentMessage', Yii::t('comments', 'RequiredComment')); } } $this->redirect(Yii::app()->createUrl($_GET['module'] . '/' . $_GET['action'], array('id' => $_GET['id'], '#' => 'comment-' . $model->primaryKey))); }
/** * This method is invoked right before an action is to be executed (after all possible filters.) * @param CAction $action the action to be executed. * @return boolean whether the action should be executed */ public function beforeAction($action) { $response = false; if (Yii::app()->user->getState('project_selected') != null) { if (in_array($action->id, array('update', 'delete', 'index', 'create'))) { $response = Budgets::model()->countBudgetsByProject((int) $_GET['owner'], Yii::app()->user->getState('project_selected')) > 0 ? true : false; } else { $response = true; } } else { $response = false; } if (!$response) { throw new CHttpException(403, Yii::t('site', '403_Error')); } else { return $response; } }
include_once 'globals.php'; include_once 'db.php'; include_once 'tables.php'; session_start(); if (isset($_COOKIE["LoginCookie"])) { $safe_token = mysqli_escape_string(db(), $_COOKIE["LoginCookie"]); $sql = "select user_id from login_cookie where token = '{$safe_token}';"; $rs = mysqli_query(db(), $sql); diesql($rs, $sql); $found = false; while ($row = mysqli_fetch_array($rs)) { $found = true; $id = $row['user_id']; $_SESSION[SESSION_LOGGED_IN_KEY] = $id; $_SESSION[SESSION_ADMIN_KEY] = false; $_SESSION[SESSION_BUDGET_ID] = Budgets::budget_for_user_id($id); if (!isset($_SESSION[SESSION_MONTH_ID])) { $month = Months::current_month(); $_SESSION[SESSION_MONTH_ID] = $month->id; $_SESSION[SESSION_MONTH_NAME] = $month->name; } } if (!$found) { header("location: profile.php"); die; } } if (!isset($_SESSION[SESSION_LOGGED_IN_KEY])) { header("location: profile.php"); die; }
<p>Add user Id to budget It</p> <p>Budget ID <input type="text" name="b_id"></p> <p>Username<input type="text" name="username"></p> <input type="submit" name="Add"> </form> <h3>Budgets</h3> <?php $budgets = Budgets::all(); foreach ($budgets as $b) { $txt = <<<EOT <h3>{$b->id} {$b->name}</h3> <ul> EOT; echo $txt; $users = Budgets::users($b->id); foreach ($users as $u) { $txt = <<<RGDM <li>{$u->username}</li> RGDM; echo "{$txt}</ol>"; } } ?> </div> <?php include 'admin_footer.php'; ?>
public function getProjectCost($project_id) { return Budgets::model()->with('BudgetsConcepts')->find(array('select' => 't.budget_id AS c, SUM(BudgetsConcepts.budgetsConcept_amount) AS total', 'condition' => 't.project_id = :project_id AND t.status_id IN (' . implode(',', array(Status::STATUS_ACCEPTED, Status::STATUS_PENDING)) . ')', 'params' => array(':project_id' => $project_id), 'group' => 't.budget_id', 'together' => true)); }
public function hasItems() { $selected = Yii::app()->user->getState('project_selected'); return Budgets::model()->count(array('condition' => 't.project_id = :project_id', 'params' => array(':project_id' => $selected))); }
/** * Lists all models. * @return index view */ public function actionIndex() { // check if user has permission to indexInvoices if (Yii::app()->user->checkAccess('indexInvoices')) { // create Expense form search $model = new InvoicesSearchForm(); $model->search(); $model->unsetAttributes(); // clear any default values $Budgets = Budgets::model()->findBudgetsByProjects(Yii::app()->user->getState('project_selected')); // set model attributes from invoices form if (isset($_GET['InvoicesSearchForm'])) { $model->attributes = $_GET['InvoicesSearchForm']; } $this->render('index', array('model' => $model, 'status' => Status::model()->findAllRequired(true), 'budgets' => $Budgets)); } else { throw new CHttpException(403, Yii::t('site', '403_Error')); } }