/** * Change Case status using select-box */ public function actionChangeStatus() { // check if user has permissions to changeStatusCases if (Yii::app()->user->checkAccess('changeStatusCases')) { // verify is request was made via post ajax if (Yii::app()->request->isAjaxRequest && isset($_POST)) { // get Cases object model $model = $this->loadModel($_REQUEST['id']); // set new status $model->status_id = $_POST['changeto']; // validate and save if ($model->save()) { // save log $attributes = array('log_date' => date("Y-m-d G:i:s"), 'log_activity' => 'CaseStatusChanged', 'log_resourceid' => $model->case_id, 'log_type' => Logs::LOG_UPDATED, 'user_id' => Yii::app()->user->id, 'module_id' => Yii::app()->controller->id, 'project_id' => $model->project_id); Logs::model()->saveLog($attributes); // create comment to let then know that some user change the case status $modelComment = new Comments(); $modelComment->comment_date = date("Y-m-d G:i:s"); $modelComment->comment_text = Status::STATUS_COMMENT . ": " . $model->Status->status_id; $modelComment->user_id = Yii::app()->user->id; $modelComment->module_id = Modules::model()->find(array('condition' => 't.module_name = :module_name', 'params' => array(':module_name' => $this->getId())))->module_id; $modelComment->comment_resourceid = $model->case_id; $modelComment->save(false); // prepare email template for each project manager Yii::import('application.extensions.phpMailer.yiiPhpMailer'); $mailer = new yiiPhpMailer(); $subject = Yii::t('email', 'CaseStatusChange') . " - " . $model->case_name; //$Users = Users::model()->with('Clients')->findManagersByProject($model->project_id); $Users = Projects::model()->findAllUsersByProject($model->project_id); $recipientsList = array(); foreach ($Users as $client) { $recipientsList[] = array('name' => $client->CompleteName, 'email' => $client->user_email); } // load template $str = $this->renderPartial('//templates/cases/StatusChanged', array('case' => $model, 'user' => Users::model()->findByPk(Yii::app()->user->id), 'urlToCase' => "http://" . $_SERVER['SERVER_NAME'] . Yii::app()->createUrl('cases/view', array('id' => $model->case_id)), 'typeNews' => $model->status_id == Status::STATUS_ACCEPTED || $model->status_id == Status::STATUS_TOREVIEW ? 'buenas' : 'malas', 'applicationName' => Yii::app()->name, 'applicationUrl' => "http://" . $_SERVER['SERVER_NAME'] . Yii::app()->request->baseUrl), true); $mailer->pushMail($subject, $str, $recipientsList, Emails::PRIORITY_NORMAL); $output = Yii::t('cases', 'StatusChanged'); } else { $output = Yii::t('cases', 'StatusError'); } echo $output; Yii::app()->end(); } else { throw new CHttpException(403, Yii::t('site', '403_Error')); } } else { throw new CHttpException(403, Yii::t('site', '403_Error')); } }
public function actionMilestonesPending() { $Milestones = Milestones::model()->MilestoneWithPendingTasks(); foreach ($Milestones as $milestone) { $Tasks = Tasks::model()->findTaskByMilestone($milestone->milestone_id); $str = CBaseController::renderInternal(Yii::app()->params['templatesPath'] . '/milestones/overdueMilestones.php', array('user' => $milestone->Users->completeName, 'tasks' => $Tasks, 'applicationName' => Yii::app()->name, 'applicationUrl' => "http://localhost/celestic/" . Yii::app()->request->baseUrl), true); $subject = Yii::t('email', 'overdueMilestone'); Yii::import('application.extensions.phpMailer.yiiPhpMailer'); $mailer = new yiiPhpMailer(); $mailer->pushMail($subject, $str, array('name' => $milestone->Users->CompleteName, 'email' => $milestone->Users->user_email), Emails::PRIORITY_NORMAL); } }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { // verify if user has permissions to createDownloads if (Yii::app()->user->checkAccess('createDownloads')) { // create object model Documents $model = new Documents(); // verify _POST['Documents'] exist if (isset($_POST['Documents'])) { // set form elements to Documents model attributes $model->attributes = $_POST['Documents']; $model->project_id = Yii::app()->user->getState('project_selected'); $model->user_id = Yii::app()->user->id; // verify file upload exist if (isset($_FILES['Documents']['name']['image']) && !empty($_FILES['Documents']['name']['image'])) { // create an instance of uploaded file $model->image = CUploadedFile::getInstance($model, 'image'); if (!$model->image->getError()) { // name is formed by date(day+month+year+hour+minutes+seconds+dayofyear+microtime()) $this->tmpFileName = str_replace(" ", "", date('dmYHis-z-') . microtime()); // get the file extension $extension = $model->image->getExtensionName(); if ($model->image->saveAs(DocumentsController::FOLDERIMAGES . $this->tmpFileName . '.' . $extension)) { // set other attributes $model->document_path = DocumentsController::FOLDERIMAGES . $this->tmpFileName . '.' . $extension; $model->document_revision = '1'; $model->document_uploadDate = date("Y-m-d"); $model->document_type = $model->image->getType(); $model->document_baseRevision = date('dmYHis'); $model->user_id = Yii::app()->user->id; // create email object Yii::import('application.extensions.phpMailer.yiiPhpMailer'); $mailer = new yiiPhpMailer(); $subject = Yii::t('email', 'newDocumentUpload') . " - " . $model->document_name; // find users managers to send email $Users = Projects::model()->findManagersByProject($model->project_id); // create array of users destinations $recipientsList = array(); foreach ($Users as $client) { $recipientsList[] = array('name' => $client->CompleteName, 'email' => $client->user_email); } // set layout then send $str = $this->renderPartial('//templates/documents/newUpload', array('document' => $model, 'urlToDocument' => "http://" . $_SERVER['SERVER_NAME'] . Yii::app()->createUrl('documents/view', array('id' => $model->document_id)), 'applicationName' => Yii::app()->name, 'applicationUrl' => "http://" . $_SERVER['SERVER_NAME'] . Yii::app()->request->baseUrl), true); $mailer->pushMail($subject, $str, $recipientsList, Emails::PRIORITY_NORMAL); } } else { $model->addError('image', $model->image->getError()); } } // validate and save if ($model->save()) { // save log $attributes = array('log_date' => date("Y-m-d G:i:s"), 'log_activity' => 'DocumentCreated', 'log_resourceid' => $model->primaryKey, 'log_type' => 'created', 'user_id' => Yii::app()->user->id, 'module_id' => Yii::app()->controller->id, 'project_id' => $model->project_id); Logs::model()->saveLog($attributes); $this->redirect(array('view', 'id' => $model->document_id)); } } // response with create view $this->render('create', array('model' => $model)); } else { throw new CHttpException(403, Yii::t('site', '403_Error')); } }
/** * 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))); }
public function actionRecover() { // create ForgottenPasswordForm object $model = new ForgottenPasswordForm(); // verify if ForgottenPasswordForm was used if (isset($_POST['ForgottenPasswordForm'])) { $model->attributes = $_POST['ForgottenPasswordForm']; // validate model if ($model->validate()) { // criteria object used to find all user data information $userCriteria = new CDbCriteria(); $userCriteria->condition = "user_email = :user_email"; $userCriteria->params = array(':user_email' => $model->user_email); $CountUser = Users::model()->count($userCriteria); $transaction = Yii::app()->db->beginTransaction(); if ($CountUser > 0) { $user = Users::model()->find($userCriteria); // -- Password Generator $vowels = 'aeiou'; $consonants = 'bcdfghjklmnpqrstvwxyz'; $password = ''; $alt = time() % 2; for ($i = 0; $i < 10; $i++) { if ($alt == 1) { $password .= $consonants[rand() % strlen($consonants)]; $alt = 0; } else { $password .= $vowels[rand() % strlen($vowels)]; $alt = 1; } } $user->user_password = md5($password); if ($user->save(false)) { $str = $this->renderPartial('//templates/users/PasswordChanged', array('userRequest' => $user->CompleteName, 'user_email' => $user->user_email, 'user_password' => $password, 'applicationName' => Yii::app()->name, 'applicationUrl' => "http://" . $_SERVER['SERVER_NAME'] . Yii::app()->request->baseUrl), true); $subject = Yii::t('email', 'PasswordReset'); Yii::import('application.extensions.phpMailer.yiiPhpMailer'); $mailer = new yiiPhpMailer(); $mailer->Ready($subject, $str, array('name' => $user->CompleteName, 'email' => $user->user_email), Emails::PRIORITY_NORMAL); Yii::app()->user->setFlash('PasswordSuccessChanged', Yii::t('site', 'PasswordSuccessChanged')); $this->refresh(); } else { throw new CException('Error #000001'); } } else { throw new CException(Yii::t('site', 'EmailNotExist')); } } } $this->layout = 'login'; $this->render('recover', array('model' => $model)); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { if (Yii::app()->user->checkAccess('createTasks')) { $model = new Tasks(); $Milestones = Milestones::model()->with('Projects.Company.Cusers')->together()->findAll(array('condition' => 'Cusers.user_id = :user_id AND t.project_id = :project_id AND Projects.project_endDate > CURDATE()', 'params' => array(':user_id' => Yii::app()->user->id, ':project_id' => Yii::app()->user->getState('project_selected')))); $Cases = Cases::model()->with('Projects.Company.Cusers')->together()->findAll(array('condition' => 'Cusers.user_id = :user_id AND t.project_id = :project_id', 'params' => array(':user_id' => Yii::app()->user->id, ':project_id' => Yii::app()->user->getState('project_selected')))); if (isset($_POST['Tasks'])) { $model->attributes = $_POST['Tasks']; $model->user_id = Yii::app()->user->id; $model->status_id = Status::STATUS_PENDING; $model->project_id = Yii::app()->user->getState('project_selected'); $model->task_startDate = date("Y-m-d"); //new CDbExpression('NOW()'); if ($model->save()) { // Guardar log $attributes = array('log_date' => date("Y-m-d G:i:s"), 'log_activity' => 'TaskCreated', 'log_resourceid' => $model->primaryKey, 'log_type' => 'created', 'user_id' => Yii::app()->user->id, 'module_id' => Yii::app()->controller->id, 'project_id' => $model->project_id); Logs::model()->saveLog($attributes); // avisar a los participantes del proyecto que una nueva tarea se ha agregado $Users = Projects::model()->findAllUsersByProject($model->project_id); $recipientsList = array(); foreach ($Users as $user) { $recipientsList[] = array('name' => $user->CompleteName, 'email' => $user->user_email); } $subject = Yii::t('email', 'TaskStatusChanged') . " - " . $model->task_name; $str = $this->renderPartial('//templates/tasks/statusChanged', array('task' => $model, 'username' => Yii::app()->user->CompleteName, 'task_url' => "http://" . $_SERVER['SERVER_NAME'] . Yii::app()->createUrl('tasks/view', array('id' => $model->task_id)), 'applicationName' => Yii::app()->name, 'applicationUrl' => "http://" . $_SERVER['SERVER_NAME'] . Yii::app()->request->baseUrl), true); Yii::import('application.extensions.phpMailer.yiiPhpMailer'); $mailer = new yiiPhpMailer(); $mailer->pushMail($subject, $str, $recipientsList, Emails::PRIORITY_NORMAL); $this->redirect(array('view', 'id' => $model->task_id)); } } $this->render('create', array('model' => $model, 'status' => Status::model()->findAll(), 'types' => TaskTypes::model()->findAll(), 'stages' => TaskStages::model()->findAll(), 'milestones' => $Milestones, 'cases' => $Cases, 'allowEdit' => true)); } else { throw new CHttpException(403, Yii::t('site', '403_Error')); } }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { if (Yii::app()->user->checkAccess('createUsers')) { $model = new Users(); $address = new Address(); if (isset($_POST['Users']) && isset($_POST['Address'])) { $model->attributes = $_POST['Users']; $address->attributes = $_POST['Address']; $model->account_id = Users::model()->findByPk(Yii::app()->user->id)->account_id; $valid = $address->validate(); $valid = $model->validate() && $valid; if ($valid) { $address->save(false); $model->address_id = $address->primaryKey; $passBeforeMD5 = $model->user_password; $model->user_password = md5($model->user_password); if ($model->save(false)) { // Guardar log $attributes = array('log_date' => date("Y-m-d G:i:s"), 'log_activity' => 'UserCreated', 'log_resourceid' => $model->primaryKey, 'log_type' => 'created', 'user_id' => Yii::app()->user->id, 'module_id' => Yii::app()->controller->id); Logs::model()->saveLog($attributes); $str = $this->renderPartial('//templates/users/invitation', array('userCreateInvitation' => Yii::app()->user->CompleteName, 'user_email' => $model->user_email, 'user_password' => $passBeforeMD5, 'userInvited' => $model->CompleteName, 'applicationName' => Yii::app()->name, 'applicationUrl' => "http://" . $_SERVER['SERVER_NAME'] . Yii::app()->request->baseUrl), true); $subject = Yii::t('email', 'UserInvitation'); Yii::import('application.extensions.phpMailer.yiiPhpMailer'); $mailer = new yiiPhpMailer(); //$mailer->Ready($subject, $str, array('email'=>$model->user_email, 'name'=>$model->CompleteName)); $mailer->pushMail($subject, $str, array('email' => $model->user_email, 'name' => $model->CompleteName), Emails::PRIORITY_NORMAL); $this->redirect(array('view', 'id' => $model->user_id)); } } } $this->render('create', array('model' => $model, 'allowEdit' => true, 'userManager' => true, 'address' => $address)); } else { throw new CHttpException(403, Yii::t('site', '403_Error')); } }
private function sendEmailAlert($attributes) { $recipients = Users::model()->with('Companies.Projects')->findAll(array('condition' => 'Projects.project_id = ' . $attributes['project_id'], 'together' => true)); $recipientsList = array(); foreach ($recipients as $user) { array_push($recipientsList, $user->user_email); } $str; Yii::import('application.extensions.miniTemplator.miniTemplator'); $t = new miniTemplator(); $t->readTemplateFromFile("templates/ActivityCreation.tpl"); $t->setVariable("applicationName", Yii::app()->name); $t->setVariable("project", Projects::model()->findByPk($attributes['project_id'])->project_name); $t->setVariable("logActivity", $attributes['log_activity']); $t->setVariable("activityCreatedByUser", Users::model()->findByPk($attributes['user_id'])->CompleteName); $t->setVariable("date", $attributes['log_date']); $t->setVariable("applicationUrl", "http://" . $_SERVER['SERVER_NAME'] . Yii::app()->request->baseUrl); $t->generateOutputToString($str); $subject = "Activity Notification"; Yii::import('application.extensions.phpMailer.yiiPhpMailer'); $mailer = new yiiPhpMailer(); $mailer->Ready($subject, $str, $recipientsList); }
/** * Creates a new model. * @return create view */ public function actionCreate() { // check if user has permissions to createClients if (Yii::app()->user->checkAccess('createClients')) { // create Users object model $modelUsers = new Users(); // create Address object model $address = new Address(); // if Users and Address form exist and was sent if (isset($_POST['Users']) && isset($_POST['Address'])) { // set form elements to Users model attributes $modelUsers->attributes = $_POST['Users']; // set form elements to Address model attributes $address->attributes = $_POST['Address']; $modelUsers->user_admin = 0; $modelUsers->account_id = Yii::app()->user->Accountid; // validate both models $valid = $address->validate(); $valid = $modelUsers->validate() && $valid; if ($valid) { // save address $address->save(false); $modelUsers->address_id = $address->primaryKey; // temporary variable with user password $passBeforeMD5 = $modelUsers->user_password; // hashed user password $modelUsers->user_password = md5($modelUsers->user_password); // save user if ($modelUsers->save(false)) { // create clients object $model = new Clients(); $model->user_id = $modelUsers->user_id; // validate and save if ($model->save()) { // save log $attributes = array('log_date' => date("Y-m-d G:i:s"), 'log_activity' => 'ClientCreated', 'log_resourceid' => $model->primaryKey, 'log_type' => Logs::LOG_CREATED, 'user_id' => Yii::app()->user->id, 'module_id' => Yii::app()->controller->id); Logs::model()->saveLog($attributes); // prepare to send email template to new user $str = $this->renderPartial('//templates/users/invitation', array('userCreateInvitation' => Yii::app()->user->CompleteName, 'user_email' => $modelUsers->user_email, 'user_password' => $passBeforeMD5, 'userInvited' => $modelUsers->CompleteName, 'applicationName' => Yii::app()->name, 'applicationUrl' => "http://" . $_SERVER['SERVER_NAME'] . Yii::app()->request->baseUrl), true); $subject = Yii::t('email', 'UserInvitation'); Yii::import('application.extensions.phpMailer.yiiPhpMailer'); $mailer = new yiiPhpMailer(); $mailer->pushMail($subject, $str, array('email' => $modelUsers->user_email, 'name' => $modelUsers->CompleteName), Emails::PRIORITY_NORMAL); // to prevent F5 keypress, redirect to view detail page $this->redirect(array('view', 'id' => $model->client_id)); } } } } $this->render('create', array('model' => $modelUsers, 'address' => $address)); } else { throw new CHttpException(403, Yii::t('site', '403_Error')); } }
/** * Add relation between user and company */ public function actionAddUsers() { // check if user has permissions to addusersCompanies if (Yii::app()->user->checkAccess('addusersCompanies')) { // account_id used to find all users in my account $account_id = Users::model()->findByPk(Yii::app()->user->id)->account_id; // verify params request if (Yii::app()->request->isAjaxRequest && isset($_POST['action'])) { // users and clients filter if ($_POST['action'] == 'useradd') { $availableUsers = Users::model()->findUsersByAccount($account_id, $_GET['owner']); } elseif ($_POST['action'] == 'clientadd') { $availableUsers = Users::model()->findClientsByAccount($account_id, $_GET['owner']); } else { throw new CHttpException(403, Yii::t('site', '403_Error')); } $html = $this->renderPartial('_dropdownUsersList', array('availableUsers' => $availableUsers), true); echo $html; Yii::app()->end(); } if (Yii::app()->request->isAjaxRequest) { // create object model for CompaniesHasUsers $model = new CompaniesHasUsers(); if (Yii::app()->request->isPostRequest) { // set params to CompaniesHasUsers attributes $_POST['CompaniesHasUsers'] = array('user_id' => $_POST['icls'], 'company_id' => $_POST['owner']); $model->attributes = $_POST['CompaniesHasUsers']; // perform validation $error = CActiveForm::validate($model, array('user_id', 'company_id')); if ($error == '[]') { // output json array $result = array(); // save new user - company relation if ($model->save()) { $result['hasreg'] = isset($_POST['iclstyp']) && (int) $_POST['iclstyp'] == 0 ? (bool) CompaniesHasUsers::model()->HasUsersAvailablesToAdd(Yii::app()->user->Accountid, $model->company_id) : (bool) CompaniesHasUsers::model()->HasClientsAvailablesToAdd(Yii::app()->user->Accountid, $model->company_id); $result['saved'] = true; if (isset($_GET['action']) && !empty($_GET['action']) && $_GET['action'] == 'useradd') { $availableUsers = Users::model()->findUsersByAccount(Yii::app()->user->Accountid, $model->company_id); } else { $availableUsers = Users::model()->findClientsByAccount(Yii::app()->user->Accountid, $model->company_id); } $html = $this->renderPartial('_dropdownUsersList', array('availableUsers' => $availableUsers), true); $result['html'] = $html; $userSelected = Users::model()->findByPk($model->user_id); // template to send mail $str = $this->renderPartial('//templates/companies/useradd', array('userCreateInvitation' => Yii::app()->user->CompleteName, 'userInvited' => $userSelected->CompleteName, 'companyName' => $model->Company->company_name, 'applicationName' => Yii::app()->name, 'applicationUrl' => "http://" . $_SERVER['SERVER_NAME'] . Yii::app()->request->baseUrl), true); $subject = Yii::t('email', 'UserAddtoCompany'); Yii::import('application.extensions.phpMailer.yiiPhpMailer'); $mailer = new yiiPhpMailer(); $mailer->pushMail($subject, $str, array('email' => $userSelected->user_email, 'name' => $userSelected->CompleteName), Emails::PRIORITY_NORMAL); } else { $result['hasreg'] = isset($_POST['iclstyp']) && (int) $_POST['iclstyp'] == 0 ? (bool) CompaniesHasUsers::model()->HasUsersAvailablesToAdd(Yii::app()->user->Accountid, $model->company_id) : (bool) CompaniesHasUsers::model()->HasClientsAvailablesToAdd(Yii::app()->user->Accountid, $model->company_id); $result['saved'] = false; } echo CJSON::encode($result); Yii::app()->end(); } else { echo $error; Yii::app()->end(); } } else { throw new CHttpException(403, Yii::t('site', '403_Error')); } } else { throw new CHttpException(403, Yii::t('site', '403_Error')); } } else { throw new CHttpException(403, Yii::t('site', '403_Error')); } }
/** * Create client user as project participant */ public function actionAddClient() { // check if user has permissions to updateProjects if (Yii::app()->user->checkAccess('updateProjects') && Yii::app()->user->getIsManager()) { // verify params request if (Yii::app()->request->isAjaxRequest) { // verify params request if (Yii::app()->request->isPostRequest) { // create object to save relation between user and project as manager $model = new ProjectsHasUsers(); $model->user_id = $_POST['uid']; $model->project_id = (int) Yii::app()->user->getState('project_selected'); if ($model->save()) { // find data for project and user to send an email $userSelected = Users::model()->findByPk($model->user_id); $project = Projects::model()->findByPk($model->project_id); // prepares to send email to user added to PM $str = $this->renderPartial('//templates/projects/useradd', array('userCreateInvitation' => Yii::app()->user->CompleteName, 'userInvited' => $userSelected->CompleteName, 'projectName' => $project->project_name, 'applicationName' => Yii::app()->name, 'applicationUrl' => "http://" . $_SERVER['SERVER_NAME'] . Yii::app()->request->baseUrl), true); $subject = Yii::t('email', 'UserAddtoProject'); Yii::import('application.extensions.phpMailer.yiiPhpMailer'); $mailer = new yiiPhpMailer(); $mailer->pushMail($subject, $str, array('email' => $userSelected->user_email, 'name' => $userSelected->CompleteName), Emails::PRIORITY_NORMAL); // save log $attributes = array('log_date' => date("Y-m-d G:i:s"), 'log_activity' => 'ClientAssigned', 'log_resourceid' => $model->project_id, 'log_type' => Logs::LOG_ASSIGNED, 'user_id' => Yii::app()->user->id, 'module_id' => Yii::app()->controller->id, 'project_id' => $model->project_id); Logs::model()->saveLog($attributes); $managers = Projects::model()->findManagersByProject((int) Yii::app()->user->getState('project_selected')); $managerList = array(); if (count($managers) > 0) { foreach ($managers as $users) { array_push($managerList, $users->user_id); } } else { array_push($managerList, -1); } $ManagersAvailables = Users::model()->findAll(array('condition' => 'Companies.company_id = :company_id AND t.user_id NOT IN (' . implode(",", $managerList) . ')', 'params' => array(':company_id' => Projects::model()->findByPk(Yii::app()->user->getState('project_selected'))->company_id), 'together' => true, 'order' => 't.user_name ASC', 'with' => array('Companies'))); $availablesClients = Users::model()->filterManagers($managerList)->findClientsByProject(Yii::app()->user->getState('project_selected')); $str = $this->renderPartial('_dropdownUsersList', array('availablesManagers' => $availablesClients), true); $strManager = $this->renderPartial('_dropdownUsersList', array('availablesManagers' => $ManagersAvailables), true); // output is a json denotation result $output = array('saved' => true, 'html' => $str, 'htmlManager' => $strManager, 'hasreg' => count($availablesClients) > 0 ? true : false); } } else { throw new CHttpException(403, Yii::t('site', '403_Error')); } echo CJSON::encode($output); Yii::app()->end(); } else { throw new CHttpException(403, Yii::t('site', '403_Error')); } } else { throw new CHttpException(403, Yii::t('site', '403_Error')); } }
/** * Creates a new model. * @return create view */ public function actionCreate() { // check if user has permissions to createInvoices if (Yii::app()->user->checkAccess('createInvoices')) { // create Invoices object model $model = new Invoices(); // find all budgets relateds to current project $Budgets = Budgets::model()->findBudgetsByProjects(Yii::app()->user->getState('project_selected')); // if Invoices form exist if (isset($_POST['Invoices'])) { // set form elements to Invoices model attributes $model->attributes = $_POST['Invoices']; $model->project_id = Yii::app()->user->getState('project_selected'); $model->status_id = Status::STATUS_PENDING; // validate and save if ($model->save()) { // save log $attributes = array('log_date' => date("Y-m-d G:i:s"), 'log_activity' => 'InvoiceCreated', 'log_resourceid' => $model->primaryKey, 'log_type' => Logs::LOG_CREATED, 'user_id' => Yii::app()->user->id, 'module_id' => Yii::app()->controller->id, 'project_id' => $model->project_id); Logs::model()->saveLog($attributes); $project = Projects::model()->findByPk(Yii::app()->user->getState('project_selected')); // send an email to projects managers only $recipientsList = array(); $ProjectManagers = Projects::model()->findManagersByProject($project->project_id); $managersArray = array(); foreach ($ProjectManagers as $manager) { $managersArray['email'] = $manager->user_email; $managersArray['name'] = $manager->CompleteName; array_push($recipientsList, $managersArray); } // prepare template to send via email $str = $this->renderPartial('//templates/invoices/activity', array('model' => $model, 'projectName' => $project->project_name, 'userposted' => Yii::app()->user->CompleteName, 'applicationName' => Yii::app()->name, 'applicationUrl' => Yii::app()->createAbsoluteUrl('invoices/view', array('id' => $model->primaryKey))), true); Yii::import('application.extensions.phpMailer.yiiPhpMailer'); $mailer = new yiiPhpMailer(); $subject = Yii::t('email', 'InvoiceCreated') . " - " . $project->project_name; $mailer->pushMail($subject, $str, $recipientsList, Emails::PRIORITY_NORMAL); // to prevent F5 keypress, redirect to create page $this->redirect(array('view', 'id' => $model->invoice_id)); } } $this->render('create', array('invoice' => $model, 'lastused' => Invoices::model()->getLastUsed(), 'budgets' => $Budgets)); } else { throw new CHttpException(403, Yii::t('site', '403_Error')); } }
/** * Creates a new model. * @return create view */ public function actionCreate() { // check if user has permissions to createMilestones if (Yii::app()->user->checkAccess('createMilestones')) { // create Milestones object model $model = new Milestones(); // find all project managers $Users = Projects::model()->findManagersByProject(Yii::app()->user->getState('project_selected')); // if Milestones form exist if (isset($_POST['Milestones'])) { // set form elements to Milestones model attributes $model->attributes = $_POST['Milestones']; $model->project_id = Yii::app()->user->getState('project_selected'); // validate milestone model if ($model->validate()) { // find milestones dates $milestone_startdate = date("Ymd", strtotime($model->milestone_startdate)); $milestone_duedate = date("Ymd", strtotime($model->milestone_duedate)); // get project data $project = Projects::model()->findByPk($model->project_id); // find project dates $project_startDate = date("Ymd", strtotime($project->project_startDate)); $project_endDate = date("Ymd", strtotime($project->project_endDate)); // If milestone dates are not within project dates ERROR!! if ($milestone_startdate >= $project_startDate && $milestone_startdate <= $project_endDate) { if ($milestone_duedate <= $project_endDate && $milestone_duedate >= $project_startDate) { // validate and save if ($model->save()) { // save log $attributes = array('log_date' => date("Y-m-d G:i:s"), 'log_activity' => 'MilestoneCreated', 'log_resourceid' => $model->primaryKey, 'log_type' => Logs::LOG_CREATED, 'user_id' => Yii::app()->user->id, 'module_id' => Yii::app()->controller->id, 'project_id' => $model->project_id); Logs::model()->saveLog($attributes); // notify to user that has a milestone to attend Yii::import('application.extensions.phpMailer.yiiPhpMailer'); $mailer = new yiiPhpMailer(); $subject = Yii::t('email', 'MilestoneAssigned') . " :: " . $model->milestone_title; // user you will be notified $User = Users::model()->findByPk($model->user_id); $recipientsList = array('name' => $User->CompleteName, 'email' => $User->user_email); // render template $str = $this->renderPartial('//templates/milestones/assigned', array('milestone' => $model, 'urlToMilestone' => Yii::app()->createAbsoluteUrl('milestones/view', array('id' => $model->milestone_id)), 'applicationName' => Yii::app()->name, 'applicationUrl' => "http://" . $_SERVER['SERVER_NAME'] . Yii::app()->request->baseUrl), true); $mailer->pushMail($subject, $str, $recipientsList, Emails::PRIORITY_NORMAL); // to prevent F5 keypress, redirect to create page $this->redirect(array('view', 'id' => $model->milestone_id)); } } else { $model->addError('milestone_duedate', Yii::t('milestones', 'DueDateError')); } } else { $model->addError('milestone_startdate', Yii::t('milestones', 'StartDateError')); } } } $this->render('create', array('model' => $model, 'users' => $Users)); } else { throw new CHttpException(403, Yii::t('site', '403_Error')); } }