Beispiel #1
0
 /**
  * Updates a particular model.
  * If update is successful, the browser will be redirected to the 'show' page.
  */
 public function actionUpdate()
 {
     $model = $this->loadModel();
     // explicitly set model scenario to be current action
     //$model->setScenario($this->action->id);
     // whether data is passed
     if (isset($_POST['Location'])) {
         // collect user input data
         $model->attributes = $_POST['Location'];
         // validate with the current action as scenario and save without validation
         if (($validated = $model->validate()) !== false && ($saved = $model->save(false)) !== false) {
             // set success message
             MUserFlash::setTopSuccess(Yii::t('hint', 'The "{title}" location record has been updated.', array('{title}' => MHtml::wrapInTag($model->title, 'strong'))));
             // go to the 'show' page
             $this->redirect(array('show', 'id' => $model->id));
         }
     }
     $this->render($this->action->id, array('model' => $model));
 }
Beispiel #2
0
 /**
  * Displays the login page
  */
 public function actionLogin()
 {
     $form = new LoginForm();
     // collect user input data
     if (isset($_POST['LoginForm'])) {
         if (isset($_POST['LoginForm']['loginWithField'])) {
             // if user is logging with email, but param changed to username,
             // we should try to log him in with email.
             // if login attempt is unsuccessful, he will have to try again with username
             LoginForm::$loginWithField = $_POST['LoginForm']['loginWithField'];
             unset($_POST['LoginForm']['loginWithField']);
         }
         $form->attributes = $_POST['LoginForm'];
         // validate user input and redirect to return page if valid
         if ($form->validate()) {
             // set the welcome message
             MUserFlash::setTopSuccess(Yii::t('hint', '{screenName}, you have been successfully logged in.', array('{screenName}' => MHtml::wrapInTag(Yii::app()->user->screenName, 'strong'))));
             // user was just authenticated, but let's check anyway
             if (!Yii::app()->user->isGuest) {
                 // update user stats
                 if (($userDetails = UserDetails::model()->findByPk(Yii::app()->user->id)) !== null) {
                     $userDetails->saveAttributes(array('lastLoginTime' => time(), 'lastVisitTime' => time(), 'totalTimeLoggedIn' => $userDetails->totalTimeLoggedIn + 60));
                 } else {
                     // hmmm, user details does not exists
                     Yii::log(W3::t('system', 'Member with ID {userId} has no UserDetails record associated. Method called: {method}.', array('{userId}' => Yii::app()->user->id, '{method}' => __METHOD__ . '()')), 'error', 'w3');
                 }
             }
             // go to previous/profile page
             $url = Yii::app()->homeUrl == Yii::app()->user->returnUrl ? array('site/index') : Yii::app()->user->returnUrl;
             $this->redirect($url);
         }
     }
     if (!Yii::app()->user->isGuest) {
         // warn user if already logged in
         MUserFlash::setTopInfo(Yii::t('hint', '{screenName}, this action will log you out from your current account.', array('{screenName}' => MHtml::wrapInTag(Yii::app()->user->screenName, 'strong'))));
     }
     // display the login form
     $this->render($this->action->id, array('form' => $form));
 }
 /**
  * Updates a particular model.
  * If update is successful, the browser will be redirected to the 'show' page.
  */
 public function actionUpdate()
 {
     if (($model = $this->loadModel()) === null) {
         // model not found
         MUserFlash::setTopError(Yii::t('modelNotFound', $this->id));
         $this->redirect($this->getGotoUrl());
     }
     // explicitly set model scenario to be current action
     //$model->setScenario($this->action->id);
     // whether data is passed
     if (isset($_POST['CompanyPayment'])) {
         // collect user input data
         $model->attributes = $_POST['CompanyPayment'];
         // validate with the current action as scenario and save without validation
         if (($validated = $model->validate()) !== false && ($saved = $model->save(false)) !== false) {
             // set success message
             MUserFlash::setTopSuccess(Yii::t('hint', 'The company payment record number "{paymentNumber}" has been updated.', array('{paymentNumber}' => MHtml::wrapInTag(empty($model->paymentNumber) ? $model->id : $model->paymentNumber, 'strong'))));
             // go to the 'show' page
             $this->redirect(array('show', 'id' => $model->id));
         }
     }
     $this->render($this->action->id, array('model' => $model));
 }
Beispiel #4
0
 /**
  * Updates a particular model.
  * If update is successful, the browser will be redirected to the 'show' page.
  */
 public function actionUpdate()
 {
     $model = $this->loadModel(array('with' => array('allCompany2Project', 'allManager2Project')));
     if ($model === null) {
         // model not found
         MUserFlash::setTopError(Yii::t('modelNotFound', $this->id));
         $this->redirect($this->getGotoUrl());
     }
     // explicitly set model scenario to be current action
     //$model->setScenario($this->action->id);
     // whether data is passed
     if (isset($_POST['Project'])) {
         // collect user input data
         $model->attributes = $_POST['Project'];
         // validate with the current action as scenario and save without validation
         if (($validated = $model->validate()) !== false && ($saved = $model->save(false)) !== false) {
             if (isset($_POST['Company2Project'])) {
                 // assigned companies
                 $hasCompany = isset($model->allCompany2Project[0]->id);
                 if (!$hasCompany) {
                     $model->allCompany2Project = array(0 => new Company2Project('create'));
                     $model->allCompany2Project[0]->projectId = $model->id;
                 }
                 foreach ($model->allCompany2Project as $company2Project) {
                     // collect user input data
                     $company2Project->attributes = $_POST['Company2Project'];
                     // at the crossroads: which action is expected to be performed
                     if ($hasCompany && empty($company2Project->companyId)) {
                         // un-assigned associated record
                         $company2Project->delete();
                     } else {
                         // validate and create/update record
                         $company2Project->save();
                     }
                 }
             }
             if (isset($_POST['User2Project'])) {
                 // assigned managers
                 $hasManager = isset($model->allManager2Project[0]->id);
                 if (!$hasManager) {
                     $model->allManager2Project = array(0 => new User2Project('create'));
                     $model->allManager2Project[0]->projectId = $model->id;
                 }
                 foreach ($model->allManager2Project as $manager2Project) {
                     // collect user input data
                     $manager2Project->attributes = $_POST['User2Project'];
                     // at the crossroads: which action is expected to be performed
                     if ($hasManager && empty($manager2Project->userId)) {
                         // un-assigned associated record
                         $manager2Project->delete();
                     } else {
                         // validate and create/update record
                         $manager2Project->save();
                     }
                 }
             }
             // set success message
             MUserFlash::setTopSuccess(Yii::t('hint', 'The "{title}" project record has been updated.', array('{title}' => MHtml::wrapInTag($model->title, 'strong'))));
             // go to the 'show' page
             $this->redirect(array('show', 'id' => $model->id));
         }
     }
     if (!isset($model->allCompany2Project[0])) {
         // new associated company
         $model->allCompany2Project = array(0 => new Company2Project('create'));
         $model->allCompany2Project[0]->projectId = $model->id;
     }
     if (!isset($model->allManager2Project[0])) {
         // new associated manager
         $model->allManager2Project = array(0 => new User2Project('create'));
         $model->allManager2Project[0]->projectId = $model->id;
         $model->allManager2Project[0]->role = User2Project::MANAGER;
     }
     $this->render($this->action->id, array('model' => $model));
 }
Beispiel #5
0
 /**
  * Updates a particular model.
  * If update is successful, the browser will be redirected to the 'show' page.
  */
 public function actionUpdate()
 {
     $model = $this->loadModel(array('with' => array('allUser2Company', 'allLocation')));
     if ($model === null) {
         // model not found
         MUserFlash::setTopError(Yii::t('modelNotFound', $this->id));
         $this->redirect($this->getGotoUrl());
     }
     // explicitly set model scenario to be current action
     //$model->setScenario($this->action->id);
     // whether data is passed
     if (isset($_POST['Company'])) {
         // collect user input data
         $model->attributes = $_POST['Company'];
         // validate with the current action as scenario and save without validation
         if (($validated = $model->validate()) !== false && ($saved = $model->save(false)) !== false) {
             if (isset($_POST['User2Company'])) {
                 // assigned users
                 $hasUser = isset($model->allUser2Company[0]->id);
                 if (!$hasUser) {
                     $model->allUser2Company = array(0 => new User2Company('create'));
                     $model->allUser2Company[0]->companyId = $model->id;
                 }
                 foreach ($model->allUser2Company as $user2Company) {
                     // collect user input data
                     $user2Company->attributes = $_POST['User2Company'];
                     $user2Company->position = 'owner';
                     // at the crossroads: which action is expected to be performed
                     if ($hasUser && empty($user2Company->userId)) {
                         // un-assigned associated record
                         $user2Company->delete();
                     } else {
                         // validate and create/update record
                         $user2Company->save();
                     }
                 }
             }
             if (isset($_POST['Location'])) {
                 // assigned locations
                 if (!isset($model->allLocation[0]->id)) {
                     $model->allLocation = array(0 => new Location('create'));
                 }
                 foreach ($model->allLocation as $location) {
                     // collect user input data
                     $location->attributes = $_POST['Location'];
                     // validate and create/update record
                     if ($location->save()) {
                         $location2Record = new Location2Record('create');
                         $location2Record->locationId = $location->id;
                         $location2Record->record = get_class($model);
                         $location2Record->recordId = $model->id;
                         $location2Record->save();
                     }
                 }
             }
             // set success message
             MUserFlash::setTopSuccess(Yii::t('hint', 'The "{title}" company record has been updated.', array('{title}' => MHtml::wrapInTag($model->title, 'strong'))));
             // go to the 'show' page
             $this->redirect(array('show', 'id' => $model->id));
         }
     }
     if (!isset($model->allUser2Company[0])) {
         // new associated user
         $model->allUser2Company = array(0 => new User2Company('create'));
         $model->allUser2Company[0]->companyId = $model->id;
     }
     if (!isset($model->allLocation[0])) {
         // new associated location
         $model->allLocation = array(0 => new Location('create'));
     }
     // display the update form
     $this->render($this->action->id, array('model' => $model));
 }
Beispiel #6
0
 /**
  * Updates a particular model.
  * If update is successful, the browser will be redirected to the 'show' page.
  */
 public function actionUpdate()
 {
     if (($model = $this->loadModel(array('with' => array('allConsultant2Task')))) === null) {
         // model not found
         MUserFlash::setTopError(Yii::t('modelNotFound', $this->id));
         $this->redirect($this->getGotoUrl());
     }
     // explicitly set model scenario to be current action
     //$model->setScenario($this->action->id);
     // whether data is passed
     if (isset($_POST['Task'])) {
         // collect user input data
         $model->attributes = $_POST['Task'];
         if (!isset($_POST['Task']['companyId'])) {
             // set company based on the project
             if ($model->projectId >= 1) {
                 $criteria = new CDbCriteria();
                 $criteria->order = "`t`.`companyPriority` ASC, `t`.`id` ASC";
                 if (($company2Project = Company2Project::model()->findByAttributes(array('projectId' => $model->projectId), $criteria)) !== null) {
                     $model->companyId = $company2Project->companyId;
                 } else {
                     $model->companyId = 0;
                 }
             } else {
                 $model->companyId = 0;
             }
         }
         if ($model->projectId >= 1 && empty($model->hourlyRate)) {
             // set project's hourly rate
             if (($project = Project::model()->findByPk($model->projectId)) !== null) {
                 $model->hourlyRate = $project->hourlyRate;
             }
         }
         // validate with the current action as scenario and save without validation
         if (($validated = $model->validate()) !== false && ($saved = $model->save(false)) !== false) {
             if (isset($_POST['User2Task'])) {
                 // assigned consultants
                 $hasConsultant = isset($model->allConsultant2Task[0]->id);
                 if (!$hasConsultant) {
                     $model->allConsultant2Task = array(0 => new User2Task('create'));
                     $model->allConsultant2Task[0]->taskId = $model->id;
                 }
                 foreach ($model->allConsultant2Task as $consultant2Task) {
                     // collect user input data
                     $consultant2Task->attributes = $_POST['User2Task'];
                     // at the crossroads: which action is expected to be performed
                     if ($hasConsultant && empty($consultant2Task->userId)) {
                         // un-assigned associated record
                         $consultant2Task->delete();
                     } else {
                         // validate and create/update record
                         $consultant2Task->save();
                     }
                 }
             }
             if (($managers2Task = User2Task::model()->findAllByAttributes(array('taskId' => $model->id, 'role' => User2Task::MANAGER))) !== array()) {
                 // delete existing relation(s) between task and manager
                 foreach ($managers2Task as $manager2Task) {
                     $manager2Task->delete();
                 }
             }
             if ($model->projectId >= 1) {
                 // new relation between task and manager
                 $criteria = new CDbCriteria();
                 $criteria->order = "`t`.`userPriority` ASC, `t`.`id` ASC";
                 if (($user2Project = User2Project::model()->findByAttributes(array('projectId' => $model->projectId, 'role' => User2Project::MANAGER), $criteria)) !== null) {
                     $user2Task = new User2Task('create');
                     $user2Task->userId = $user2Project->userId;
                     $user2Task->taskId = $model->id;
                     $user2Task->role = User2Task::MANAGER;
                     $user2Task->save();
                 }
             }
             // set success message
             MUserFlash::setTopSuccess(Yii::t('hint', 'The "{title}" task record has been updated.', array('{title}' => MHtml::wrapInTag($model->title, 'strong'))));
             // go to the 'show' page
             $this->redirect(array('show', 'id' => $model->id));
         }
     }
     if (!isset($model->allConsultant2Task[0])) {
         // new associated consultant
         $model->allConsultant2Task = array(0 => new User2Task('create'));
         $model->allConsultant2Task[0]->taskId = $model->id;
         $model->allConsultant2Task[0]->role = User2Task::CONSULTANT;
     }
     // prepare model data for the form
     $model->estimateH = floor($model->estimateMinute / 60);
     $model->estimateM = fmod($model->estimateMinute, 60);
     // render the view file
     $this->render($this->action->id, array('model' => $model));
 }
Beispiel #7
0
<?php

MParams::setPageLabel(Yii::t('page', 'Migration tool'));
MLayout::hideSidebars();
$this->widget('application.components.WContentHeader', array('displayBreadcrumbs' => false));
if (!empty($message)) {
    MUserFlash::setTopSuccess($message);
} else {
    ?>
<div class="w3-main-form-box ui-widget-content ui-corner-all">

<?php 
    echo _CHtml::beginForm('', 'post', array('class' => 'w3-main-form')) . "\n";
    ?>

<div class="w3-form-row w3-first">
  <div class="w3-form-row-input w3-form-row-2columns w3-center">
    <?php 
    echo _CHtml::submitButton(Yii::t('link', 'Migrate from our old Project Management System'), array('class' => 'w3-input-button ui-state-default ui-corner-all')) . "\n";
    ?>
  </div>
  <div class="clear">&nbsp;</div>
</div>

<?php 
    echo _CHtml::endForm();
    ?>

</div><!-- w3-main-form-box -->

<?php 
Beispiel #8
0
 /**
  * Update user interface.
  * Accessible only to authenticated users and admin.
  * If update is successful, the browser will be redirected to the 'show' page.
  */
 public function actionUpdateInterface()
 {
     if (!Yii::app()->user->checkAccess($this->route, array('model' => $this->loadModel()))) {
         // access denied
         MUserFlash::setTopError(Yii::t('accessDenied', $this->route));
         $this->redirect($this->getGotoUrl());
     }
     $pkIsPassed = isset($_GET['id']);
     if (($model = $this->loadModel()) === null) {
         // model not found
         MUserFlash::setTopError(Yii::t('modelNotFound', $this->id));
         $this->redirect($this->getGotoUrl());
     }
     // explicitly set model scenario to be current action
     $model->setScenario($this->action->id);
     if (is_object($model->details)) {
         $model->details->setScenario($this->action->id);
     }
     // whether data is passed
     if (isset($_POST['User'])) {
         // collect user input data
         $model->attributes = $_POST['User'];
         // validate with the current action as scenario and save without validation
         if (($validated = $model->validate()) !== false && ($saved = $model->save(false)) !== false) {
             // take care of updateTime (this is not critical)
             $model->details->saveAttributes(array('updateTime' => time()));
             // update variables first defined in {@link _CUserIdentity} class
             if ($model->isMe) {
                 // update user states in the session for {@link _CController::init}
                 Yii::app()->user->setState('interface', $model->interface);
                 // set user preferred interface
                 if (!empty($model->interface)) {
                     W3::setInterface($model->interface);
                 }
                 // we do not need to update user cookie any more because
                 // we overrode auto-login with {@link _CWebUser::restoreFromCookie}
             }
             // set success message
             MUserFlash::setTopSuccess(Yii::t('hint', $model->isMe ? '{screenName}, new user interface has been applied.' : 'The user interface for member account "{screenName}" has been updated.', array('{screenName}' => MHtml::wrapInTag($model->screenName, 'strong'))));
             // go to 'show' page
             $this->redirect($model->isMe ? array('show') : array('show', 'id' => $model->id));
         } else {
             if ($validated && !$saved) {
                 // set error message
                 MUserFlash::setTopError(Yii::t('hint', $model->isMe ? 'Error! {screenName}, new user interface could not be applied.' : 'Error! The user interface for member account "{screenName}" could not be updated.', array('{screenName}' => MHtml::wrapInTag($model->screenName, 'strong'))));
                 Yii::log(W3::t('system', 'Could not save attributes of the {model} model. Model ID: {modelId}. Method called: {method}.', array('{model}' => get_class($model), '{modelId}' => $model->id, '{method}' => __METHOD__ . '()')), 'error', 'w3');
             }
         }
     }
     // display the update form
     $this->render($this->action->id, array('model' => $model, 'pkIsPassed' => $pkIsPassed));
 }
Beispiel #9
0
 /**
  * Deletes a particular model.
  * If deletion is successful, the browser will be redirected to the 'list' page.
  */
 public function actionDelete()
 {
     $model = $this->loadModel();
     // explicitly set model scenario to be current action
     //$model->setScenario($this->action->id);
     if (Yii::app()->request->isPostRequest) {
         // we only allow deletion via POST request
         if ($model->delete()) {
             // set success message
             MUserFlash::setTopSuccess(Yii::t('hint', 'The time record number {id} has been successfully deleted.', array('{id}' => MHtml::wrapInTag($model->id, 'strong'))));
             // go to the controller default page
             $this->redirect(array($this->id . '/'));
         } else {
             // set error message
             MUserFlash::setTopError(Yii::t('hint', 'Error! The time record number {id} could not be deleted.', array('{id}' => MHtml::wrapInTag($model->id, 'strong'))));
             Yii::log(W3::t('system', 'Could not delete the {model} model. Model ID: {modelId}. Method called: {method}.', array('{model}' => get_class($model), '{modelId}' => $model->id, '{method}' => __METHOD__ . '()')), 'error', 'w3');
         }
     }
     // render the view file
     $this->render($this->action->id, array('model' => $model));
 }