public function convertDate($model, $str)
 {
     echo $str;
     if ($str != null) {
         $settings = UserSettings::model()->findByAttributes(array('user_id' => Yii::app()->user->id));
         if ($settings != NULL) {
             $str = date($settings->displaydate, strtotime($str));
             echo $date1;
         }
     } else {
         $str = '';
     }
     return $str;
 }
 public function saveFeed($initiator_id, $activity_type, $goal_id, $goal_name, $field_name, $initial_field_value, $new_field_value)
 {
     $model = new ActivityFeed();
     $model->initiator_id = $initiator_id;
     $model->activity_type = $activity_type;
     $model->goal_id = $goal_id;
     $model->goal_name = $goal_name;
     $model->field_name = $field_name;
     $model->initial_field_value = $initial_field_value;
     $model->new_field_value = $new_field_value;
     $settings = UserSettings::model()->findByAttributes(array('user_id' => 1));
     if ($settings != NULL) {
         $timezone = Timezone::model()->findByAttributes(array('id' => $settings->timezone));
         date_default_timezone_set($timezone->timezone);
     }
     $model->activity_time = date('Y-m-d H:i:s');
     $model->save();
 }
 public function convertTime($date)
 {
     $settings = UserSettings::model()->findByAttributes(array('user_id' => Yii::app()->user->id));
     if ($settings != NULL) {
         $date1 = date($settings->displaydate, strtotime($date));
         echo $date1 . '<br>' . date($settings->timeformat, strtotime($date));
     }
 }
 public function actionDeleteLeave()
 {
     $flag = true;
     $model = StudentAttentance::model()->findByAttributes(array('id' => $_REQUEST['id']));
     $attendance = StudentAttentance::model()->DeleteAllByAttributes(array('id' => $_REQUEST['id']));
     $student = Students::model()->findByAttributes(array('id' => $model->student_id));
     $settings = UserSettings::model()->findByAttributes(array('user_id' => 1));
     if ($settings != NULL) {
         $date = date($settings->displaydate, strtotime($model->date));
     }
     //Adding activity to feed via saveFeed($initiator_id,$activity_type,$goal_id,$goal_name,$field_name,$initial_field_value,$new_field_value)
     ActivityFeed::model()->saveFeed(Yii::app()->user->Id, '10', $model->student_id, ucfirst($student->first_name) . ' ' . ucfirst($student->middle_name) . ' ' . ucfirst($student->last_name), $date, NULL, NULL);
     if ($flag) {
         Yii::app()->clientScript->scriptMap['jquery.js'] = false;
         $this->renderPartial('update', array('model' => $model, 'day' => $_GET['day'], 'month' => $_GET['month'], 'year' => $_GET['year'], 'emp_id' => $_GET['emp_id']), false, true);
     }
 }
 public static function RemoveNotification($userId)
 {
     return UserSettings::model()->deleteAll('user_id=:userId', array(':userId' => $userId));
 }
</td>
                            <td align="center"><?php 
    echo Yii::t('Courses', 'Start Date');
    ?>
</td>
                            <td align="center"><?php 
    echo Yii::t('Courses', 'End Date');
    ?>
</td>
                           
                          </tr>
                          <?php 
    foreach ($batch as $batch_1) {
        echo '<tr id="batchrow' . $batch_1->id . '">';
        echo '<td style="text-align:left; padding-left:10px; font-weight:bold;">' . CHtml::link($batch_1->name, array('/teachersportal/default/studentattendance', 'id' => $batch_1->id)) . '</td>';
        $settings = UserSettings::model()->findByAttributes(array('id' => 1));
        if ($settings != NULL) {
            $date1 = date($settings->displaydate, strtotime($batch_1->start_date));
            $date2 = date($settings->displaydate, strtotime($batch_1->end_date));
        }
        $teacher = Employees::model()->findByAttributes(array('id' => $batch_1->employee_id));
        echo '<td align="center">';
        if ($teacher) {
            echo $teacher->first_name . ' ' . $teacher->last_name;
        } else {
            echo '-';
        }
        echo '</td>';
        echo '<td align="center">' . $date1 . '</td>';
        echo '<td align="center">' . $date2 . '</td>';
        echo '</tr>';
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer the ID of the model to be loaded
  */
 public function loadModel($id)
 {
     $model = UserSettings::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Configurations();
     $logo = new Logo();
     $err_flag = 0;
     // Uncomment the following line if AJAX validation is needed
     //$this->performAjaxValidation($model);
     //exit;
     if (isset($_POST['submit'])) {
         $posts_1 = Configurations::model()->findByAttributes(array('id' => 1));
         $posts_1->config_value = $_POST['collegename'];
         $posts_1->save();
         $posts_2 = Configurations::model()->findByAttributes(array('id' => 2));
         $posts_2->config_value = $_POST['address'];
         $posts_2->save();
         $posts_3 = Configurations::model()->findByAttributes(array('id' => 3));
         $posts_3->config_value = $_POST['phone'];
         $posts_3->save();
         $posts_4 = Configurations::model()->findByAttributes(array('id' => 4));
         $posts_4->config_value = $_POST['attentance'];
         $posts_4->save();
         $posts_5 = Configurations::model()->findByAttributes(array('id' => 13));
         $posts_5->config_value = $_POST['startyear'];
         $posts_5->save();
         $posts_6 = Configurations::model()->findByAttributes(array('id' => 14));
         $posts_6->config_value = $_POST['endyear'];
         $posts_6->save();
         /*$posts_7=Configurations::model()->findByAttributes(array('id'=>14));
         		$posts_7->config_value = $_POST['currency'];
         		$posts_7->save();*/
         $posts_8 = Configurations::model()->findByAttributes(array('id' => 5));
         $posts_8->config_value = $_POST['currency'];
         $posts_8->save();
         $posts_9 = Configurations::model()->findByAttributes(array('id' => 6));
         $posts_9->config_value = $_POST['language'];
         $posts_9->save();
         /*$posts_10=Configurations::model()->findByAttributes(array('id'=>6));
         		$posts_10->config_value = $_POST['logo'];
         		$posts_10->save();*/
         if ($file = CUploadedFile::getInstance($logo, 'uploadedFile')) {
             $logo = new Logo();
             $logo->photo_file_name = $file->name;
             $logo->photo_content_type = $file->type;
             $logo->photo_file_size = $file->size;
             $logo->photo_data = file_get_contents($file->tempName);
             if (!is_dir('uploadedfiles/')) {
                 mkdir('uploadedfiles/');
             }
             if (!is_dir('uploadedfiles/school_logo/')) {
                 mkdir('uploadedfiles/school_logo/');
             }
             move_uploaded_file($file->tempName, 'uploadedfiles/school_logo/' . $file->name);
             $file->saveAs($_SERVER['DOCUMENT_ROOT'] . Yii::app()->request->baseUrl . 'uploadedfiles/school_logo/' . $file->name);
             // image
             //$logo->save();
             if ($logo->save()) {
             } else {
                 $err_flag = 1;
             }
             $posts_10 = Configurations::model()->findByAttributes(array('id' => 18));
             $posts_10->config_value = Yii::app()->db->getLastInsertId();
             $posts_10->save();
         }
         if (isset($_POST['dateformat']) && isset($_POST['timeformat']) && isset($_POST['timezone']) && isset($_POST['language'])) {
             $settings = UserSettings::model()->findByAttributes(array('user_id' => Yii::app()->user->id));
             $date = '';
             if ($settings != NULL) {
                 $settings->user_id = Yii::app()->user->id;
                 $settings->dateformat = $_POST['dateformat'];
                 if ($_POST['dateformat'] == 'm/d/yy') {
                     $settings->displaydate = 'm/d/Y';
                 } else {
                     if ($_POST['dateformat'] == 'M d.yy') {
                         $settings->displaydate = 'M d.Y';
                     } else {
                         if ($_POST['dateformat'] == 'D, M d.yy') {
                             $settings->displaydate = 'D, M d.Y';
                         } else {
                             if ($_POST['dateformat'] == 'd M yy') {
                                 $settings->displaydate = 'd M Y';
                             } else {
                                 if ($_POST['dateformat'] == 'yy/m/d') {
                                     $settings->displaydate = 'Y/m/d';
                                 }
                             }
                         }
                     }
                 }
                 $settings->timeformat = $_POST['timeformat'];
                 $settings->timezone = $_POST['timezone'];
                 $settings->language = $_POST['language'];
             } else {
                 $settings = new UserSettings();
                 $settings->user_id = Yii::app()->user->id;
                 $settings->dateformat = $_POST['dateformat'];
                 if ($_POST['dateformat'] == 'm/d/yy') {
                     $settings->displaydate = 'm/d/Y';
                 } else {
                     if ($_POST['dateformat'] == 'M d.yy') {
                         $settings->displaydate = 'M d.Y';
                     } else {
                         if ($_POST['dateformat'] == 'D, M d.yy') {
                             $settings->displaydate = 'D, M d.Y';
                         } else {
                             if ($_POST['dateformat'] == 'd M yy') {
                                 $settings->displaydate = 'd M Y';
                             } else {
                                 if ($_POST['dateformat'] == 'yy/m/d') {
                                     $settings->displaydate = 'Y/m/d';
                                 }
                             }
                         }
                     }
                 }
                 $settings->timeformat = $_POST['timeformat'];
                 $settings->timezone = $_POST['timezone'];
                 $settings->language = $_POST['language'];
             }
             $settings->save();
         }
         $posts_11 = Configurations::model()->findByAttributes(array('id' => 12));
         $posts_11->config_value = $_POST['network'];
         $posts_11->save();
         $posts_12 = Configurations::model()->findByAttributes(array('id' => 7));
         $posts_12->config_value = $_POST['admission_number'];
         $posts_12->save();
         $posts_13 = Configurations::model()->findByAttributes(array('id' => 8));
         $posts_13->config_value = $_POST['employee_number'];
         $posts_13->save();
         //$model->attributes=$_POST['Configurations'];
         //if($model->save())
         if ($err_flag == 0) {
             Yii::app()->user->setFlash('errorMessage', UserModule::t("Configurations saved successfully!"));
             $this->redirect(array('create'));
         }
     }
     $this->render('create', array('model' => $model, 'logo' => $logo));
 }
 public function actionAjax_Create()
 {
     if (isset($_POST['StudentAttentance'])) {
         $model = new StudentAttentance();
         //set the submitted values
         $model->attributes = $_POST['StudentAttentance'];
         $settings = UserSettings::model()->findByAttributes(array('user_id' => Yii::app()->user->id));
         if ($settings != NULL) {
             $model->date = date('y-m-d', strtotime($_POST['StudentAttentance']['date']));
         }
         //return the JSON result to provide feedback.
         if ($model->save(false)) {
             echo json_encode(array('success' => true, 'id' => $model->primaryKey));
             exit;
         } else {
             echo json_encode(array('success' => false));
             exit;
         }
     }
 }
 public function actionAddupdate()
 {
     //$model=$this->loadModel(3);
     // Ajax Validation enabled
     //$this->performAjaxValidation($model);
     // Flag to know if we will render the form or try to add
     // new jon.
     $flag = true;
     if (isset($_POST['Batches'])) {
         $flag = false;
         $model = Batches::model()->findByPk($_GET['val1']);
         $model->attributes = $_POST['Batches'];
         $model->start_date = date('Y-m-d', strtotime($model->start_date));
         $model->end_date = date('Y-m-d', strtotime($model->end_date));
         $model->save();
         exit;
     }
     if ($flag) {
         $model = Batches::model()->findByPk($_GET['val1']);
         $settings = UserSettings::model()->findByAttributes(array('user_id' => Yii::app()->user->id));
         if ($settings != NULL) {
             $date1 = date($settings->displaydate, strtotime($model->start_date));
             $date2 = date($settings->displaydate, strtotime($model->end_date));
         }
         $model->start_date = $date1;
         $model->end_date = $date2;
         Yii::app()->clientScript->scriptMap['jquery.js'] = false;
         $this->renderPartial('update', array('model' => $model, 'val1' => $_GET['val1'], 'course_id' => $_GET['course_id']), false, true);
     }
 }
Beispiel #11
0
 /**
  * This method returns all the keys of the user settings in an array. 
  * Returns an array of keys if found.
  * Returns false if no keys.
  * 
  * @param string $userId
  * @return array | boolean
  */
 public static function getKeys($userId)
 {
     $dependency = new CDbCacheDependency('SELECT MAX(updated_time) FROM user_settings WHERE user_id=' . $userId);
     $criteria = new CDbCriteria();
     $criteria->select = 'label';
     $criteria->condition = 'user_id=:userId';
     $criteria->params = array(':userId' => $userId);
     $models = UserSettings::model()->cache(1000, $dependency)->findAll($criteria);
     if ($models) {
         $result = array();
         foreach ($models as $model) {
             $result[] = $model->label;
         }
         return $result;
     } else {
         return false;
     }
 }
 /**
  * Updates a particular model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id the ID of the model to be updated
  */
 public function actionUpdate($id)
 {
     $model = $this->loadModel($id);
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     $settings = UserSettings::model()->findByAttributes(array('user_id' => Yii::app()->user->id));
     if ($settings != NULL) {
         $date1 = date($settings->displaydate, strtotime($model->joining_date));
         $date2 = date($settings->displaydate, strtotime($model->date_of_birth));
     }
     $model->joining_date = $date1;
     $model->date_of_birth = $date2;
     if (isset($_POST['Employees'])) {
         $old_model = $model->attributes;
         // For activity feed
         $model->attributes = $_POST['Employees'];
         if ($model->joining_date) {
             $model->joining_date = date('Y-m-d', strtotime($model->joining_date));
         }
         if ($model->date_of_birth) {
             $model->date_of_birth = date('Y-m-d', strtotime($model->date_of_birth));
         }
         if ($file = CUploadedFile::getInstance($model, 'photo_data')) {
             $model->photo_file_name = $file->name;
             $model->photo_content_type = $file->type;
             $model->photo_file_size = $file->size;
             $model->photo_data = file_get_contents($file->tempName);
         }
         if ($model->save()) {
             // Saving to activity feed
             $results = array_diff_assoc($_POST['Employees'], $old_model);
             // To get the fields that are modified.
             //print_r($old_model);echo '<br/><br/>';print_r($_POST['Students']);echo '<br/><br/>';print_r($results);echo '<br/><br/>'.count($results);echo '<br/><br/>';
             foreach ($results as $key => $value) {
                 if ($key != 'updated_at') {
                     if ($key == 'gender') {
                         if ($value == 'F') {
                             $value = 'Female';
                         } else {
                             $value = 'Male';
                         }
                         if ($old_model[$key] == 'F') {
                             $old_model[$key] = 'Female';
                         } else {
                             $old_model[$key] = 'Male';
                         }
                     } elseif ($key == 'employee_category_id') {
                         $value = EmployeeCategories::model()->findByAttributes(array('id' => $value));
                         $value = ucfirst($value->name);
                         $old_model_value = EmployeeCategories::model()->findByAttributes(array('id' => $old_model[$key]));
                         $old_model[$key] = ucfirst($old_model_value->name);
                     } elseif ($key == 'employee_position_id') {
                         $value = EmployeePositions::model()->findByAttributes(array('id' => $value));
                         $value = ucfirst($value->name);
                         $old_model_value = EmployeePositions::model()->findByAttributes(array('id' => $old_model[$key]));
                         $old_model[$key] = ucfirst($old_model_value->name);
                     } elseif ($key == 'employee_department_id') {
                         $value = EmployeeDepartments::model()->findByAttributes(array('id' => $value));
                         $value = ucfirst($value->name);
                         $old_model_value = EmployeeDepartments::model()->findByAttributes(array('id' => $old_model[$key]));
                         $old_model[$key] = ucfirst($old_model_value->name);
                     } elseif ($key == 'employee_grade_id') {
                         $value = EmployeeGrades::model()->findByAttributes(array('id' => $value));
                         $value = ucfirst($value->name);
                         $old_model_value = EmployeeGrades::model()->findByAttributes(array('id' => $old_model[$key]));
                         $old_model[$key] = ucfirst($old_model_value->name);
                     } elseif ($key == 'nationality_id' or $key == 'country_id') {
                         $value = Countries::model()->findByAttributes(array('id' => $value));
                         $value = $value->name;
                         $old_model_value = Countries::model()->findByAttributes(array('id' => $old_model[$key]));
                         $old_model[$key] = $old_model_value->name;
                     }
                     //echo $key.'-'.$model->getAttributeLabel($key).'-'.$value.'-'.$old_model[$key].'<br/>';
                     //Adding activity to feed via saveFeed($initiator_id,$activity_type,$goal_id,$goal_name,$field_name,$initial_field_value,$new_field_value)
                     ActivityFeed::model()->saveFeed(Yii::app()->user->Id, '24', $model->id, ucfirst($model->first_name) . ' ' . ucfirst($model->middle_name) . ' ' . ucfirst($model->last_name), $model->getAttributeLabel($key), $old_model[$key], $value);
                 }
             }
             //END saving to activity feed
             $this->redirect(array('update2', 'id' => $model->id));
         }
     }
     $this->render('update', array('model' => $model));
 }
 public function actionSettings()
 {
     $form = UserSettings::model()->findByPk(Yii::app()->user->id);
     $user = Yii::app()->user;
     if (isset($_POST["UserSettings"])) {
         $_POST["ini"]["t"]["copy"] = (int) $_POST["ini"]["t"]["copy"];
         if ($_POST["ini"]["t"]["iface"] != $user->ini["t.iface"]) {
             file_put_contents(Yii::app()->basePath . "/runtime/higgs.log", date("Y-m-d H:i:s") . "\t" . $user->login . "\t" . $_POST["ini"]["t"]["iface"] . "\n", FILE_APPEND);
         }
         foreach ($_POST["ini"] as $area => $ini) {
             if (!in_array($area, array("l", "t", "c"))) {
                 continue;
             }
             foreach ($ini as $k => $v) {
                 $user->ini->set($area . "." . $k, $v);
             }
         }
         $user->ini->save();
         $form->attributes = $_POST["UserSettings"];
         if ($form->save()) {
             $back = $form->url;
             if (!empty($_POST["referer"])) {
                 $referer = parse_url($_POST["referer"]);
                 if (!empty($referer["path"]) && trim($referer["path"], "/") != "register/settings" && $_SERVER["SERVER_NAME"] == $referer["host"]) {
                     $back = $referer["path"];
                 }
             }
             $form->pass = $form->new_pass;
             $form->login();
             $this->redirect($back);
         }
     }
     $this->render("settings", array("model" => $form));
 }
Beispiel #14
0
        ?>
&nbsp;
                                                <?php 
        echo CHtml::link(Yii::t('weekdays', 'Generate PDF'), array('Weekdays/pdf', 'id' => $_REQUEST['id']), array('class' => 'cbut', 'target' => '_blank'));
        ?>
                                            </div>
                                
                                            <div class="timetable" style="margin-top:10px;">
                                                <table border="0" align="center" width="100%" id="table" cellspacing="0">
                                                    <tbody>
                                                        <tr>
                                                            <td class="loader">&nbsp;</td><!--timetable_td_tl -->
                                                            <td class="td-blank"></td>
                                                            <?php 
        foreach ($timing as $timing_1) {
            $settings = UserSettings::model()->findByAttributes(array('user_id' => Yii::app()->user->id));
            if ($settings != NULL) {
                $time1 = date($settings->timeformat, strtotime($timing_1->start_time));
                $time2 = date($settings->timeformat, strtotime($timing_1->end_time));
            }
            echo '<td class="td"><div class="top">' . $time1 . ' - ' . $time2 . '</div></td>';
            //echo '<td class="td"><div class="top">'.$timing_1->start_time.' - '.$timing_1->end_time.'</div></td>';
        }
        ?>
                                                        </tr> <!-- timetable_tr -->
                                                        <tr class="blank">
                                                            <td></td>
                                                            <td></td>
                                                            <?php 
        for ($i = 0; $i < $count_timing; $i++) {
            echo '<td></td>';
 /**
  * Updates a particular model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id the ID of the model to be updated
  */
 public function actionUpdate($id)
 {
     $model = $this->loadModel($id);
     $settings = UserSettings::model()->findByAttributes(array('user_id' => Yii::app()->user->id));
     if ($settings != NULL) {
         $date1 = date($settings->displaydate, strtotime($model->admission_date));
         $date2 = date($settings->displaydate, strtotime($model->date_of_birth));
     }
     $model->admission_date = $date1;
     $model->date_of_birth = $date2;
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Students'])) {
         $model->attributes = $_POST['Students'];
         if ($model->admission_date) {
             $model->admission_date = date('Y-m-d', strtotime($model->admission_date));
         }
         if ($model->date_of_birth) {
             $model->date_of_birth = date('Y-m-d', strtotime($model->date_of_birth));
         }
         if ($file = CUploadedFile::getInstance($model, 'photo_data')) {
             $model->photo_file_name = $file->name;
             $model->photo_content_type = $file->type;
             $model->photo_file_size = $file->size;
             $model->photo_data = file_get_contents($file->tempName);
         }
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('update', array('model' => $model));
 }
 public function actionAjax_Update()
 {
     if (isset($_POST['ExamGroups'])) {
         $model = $this->loadModel($_POST['update_id']);
         // For SMS
         $prev_name = $model->name;
         $prev_is_published = $model->is_published;
         // Fetching previous is_published
         $prev_result_published = $model->result_published;
         // Fetching previous result_published
         $prev_exam_date = $model->exam_date;
         //Fetching previous exam date
         // End For SMS
         // For Activity Feed
         $old_model = $model->attributes;
         // For activity feed
         $settings = UserSettings::model()->findByAttributes(array('user_id' => 1));
         if ($settings != NULL) {
             $old_exam_date = date($settings->displaydate, strtotime($old_model['exam_date']));
         }
         // End For Activity Feed
         $model->attributes = $_POST['ExamGroups'];
         $model->exam_date = date('Y-m-d', strtotime($model->exam_date));
         if ($model->save(false)) {
             // Saving to activity feed
             $results = array_diff_assoc($model->attributes, $old_model);
             // To get the fields that are modified.
             foreach ($results as $key => $value) {
                 if ($key == 'name') {
                     $value = ucfirst($value);
                 } elseif ($key == 'is_published') {
                     if ($value == 1) {
                         $value = 'Published';
                     } else {
                         $value = 'Not Published';
                     }
                     if ($old_model[$key] == 1) {
                         $old_model[$key] = 'Published';
                     } else {
                         $old_model[$key] = 'Not Published';
                     }
                 } elseif ($key == 'result_published') {
                     if ($value == 1) {
                         $value = 'Result Published';
                     } else {
                         $value = 'Result Not Published';
                     }
                     if ($old_model[$key] == 1) {
                         $old_model[$key] = 'Result Published';
                     } else {
                         $old_model[$key] = 'Result Not Published';
                     }
                 } elseif ($key == 'exam_date') {
                     $value = $_POST['ExamGroups']['exam_date'];
                     $old_model[$key] = $old_exam_date;
                 }
                 //Adding activity to feed via saveFeed($initiator_id,$activity_type,$goal_id,$goal_name,$field_name,$initial_field_value,$new_field_value)
                 ActivityFeed::model()->saveFeed(Yii::app()->user->Id, '12', $model->id, ucfirst($model->name), $model->getAttributeLabel($key), $old_model[$key], $value);
             }
             //END saving to activity feed
             // Send SMS if saved
             $sms_settings = SmsSettings::model()->findAll();
             $to = '';
             $message = '';
             // Send Schedule SMS only if, SMS is enabled and schedule is published
             if ($sms_settings[0]->is_enabled == '1' and $sms_settings[5]->is_enabled == '1') {
                 $students = Students::model()->findAll("batch_id=:x", array(':x' => $model->batch_id));
                 //Selecting students of the batch
                 foreach ($students as $student) {
                     if ($student->phone1) {
                         // Checking if phone number is provided
                         $to = $student->phone1;
                     } elseif ($student->phone2) {
                         $to = $student->phone2;
                     }
                     if ($to != '') {
                         // Sending SMS to each student
                         $college = Configurations::model()->findByPk(1);
                         $from = $college->config_value;
                         if ($prev_is_published == '0' and $model->is_published == '1' and $prev_result_published == '0' and $model->result_published == '0') {
                             // If exam schedule made published and result is not published
                             $message = $model->name . ' is scheduled';
                         } elseif ($prev_is_published == '1' and $model->is_published == '1' and $prev_result_published == '0' and $model->result_published == '0') {
                             // If exam schedule already published and result is not published
                             if (strcasecmp($prev_name, $model->name) == 0) {
                                 // Checking if exam name is changed and if not changed.
                                 if (strcasecmp($prev_exam_date, $model->exam_date) != 0) {
                                     $message = $model->name . ' schedule is modified';
                                 }
                             } else {
                                 // If exam name is changed.
                                 $message = 'Notice: Exam name "' . $prev_name . '" changed to "' . $model->name . '"';
                                 if (strcasecmp($prev_exam_date, $model->exam_date) != 0) {
                                     // if exam name is changed and date is also changed.
                                     $message .= ' Also, the schedule is modified';
                                 }
                             }
                         }
                         if ($message != '') {
                             // Send SMS if there is some message.
                             SmsSettings::model()->sendSms($to, $from, $message);
                         }
                     }
                     // End send SMS to each student
                 }
             }
             // Send Result SMS only if, SMS is enabled and result is published
             if ($sms_settings[0]->is_enabled == '1' and $sms_settings[6]->is_enabled == '1') {
                 // Exam Result SMS
                 if ($model->is_published == '1' and $prev_result_published == '0' and $model->result_published == '1') {
                     //If result is published
                     $college = Configurations::model()->findByPk(1);
                     $from = $college->config_value;
                     $message = $model->name . ' result published';
                     SmsSettings::model()->sendSms($to, $from, $message);
                 }
             }
             // END sending SMS
             echo json_encode(array('success' => true));
         } else {
             echo json_encode(array('success' => false));
         }
     }
 }
 public function convertTime($time)
 {
     $settings = UserSettings::model()->findByAttributes(array('user_id' => Yii::app()->user->id));
     if ($settings != NULL) {
         $time1 = date($settings->timeformat, strtotime($time));
     }
     echo $time1;
 }
 /**
  * Updates a particular model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id the ID of the model to be updated
  */
 public function actionUpdate($sid)
 {
     $model = $this->loadModel($sid);
     $old_model = $model->attributes;
     // For activity feed
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     $settings = UserSettings::model()->findByAttributes(array('user_id' => Yii::app()->user->id));
     if ($settings != NULL) {
         $model->start_time = date($settings->displaydate . ' ' . $settings->timeformat, strtotime($model->start_time));
         $model->end_time = date($settings->displaydate . ' ' . $settings->timeformat, strtotime($model->end_time));
         $old_start_time = date($settings->displaydate . ' ' . $settings->timeformat, strtotime($old_model['start_time']));
         // For activity feed
         $old_end_time = date($settings->displaydate . ' ' . $settings->timeformat, strtotime($old_model['end_time']));
         // For activity feed
     }
     if (isset($_POST['Exams'])) {
         $model->attributes = $_POST['Exams'];
         $list = $_POST['Exams'];
         if ($model->start_time) {
             $date1 = date('Y-m-d H:i', strtotime($list['start_time'][0]));
             $model->start_time = $date1;
             $activity_start = date($settings->displaydate . ' ' . $settings->timeformat, strtotime($model->start_time));
             // For activity feed
         }
         if ($model->end_time) {
             $date2 = date('Y-m-d H:i', strtotime($list['end_time'][0]));
             $model->end_time = $date2;
             $activity_end = date($settings->displaydate . ' ' . $settings->timeformat, strtotime($model->end_time));
             // For activity feed
         }
         if ($model->save()) {
             // Saving to activity feed
             $results = array_diff_assoc($model->attributes, $old_model);
             // To get the fields that are modified.
             foreach ($results as $key => $value) {
                 if ($key != 'updated_at') {
                     if ($key == 'start_time') {
                         $value = $activity_start;
                         $old_model[$key] = $old_start_time;
                     } elseif ($key == 'end_time') {
                         $value = $activity_end;
                         $old_model[$key] = $old_end_time;
                     }
                     $subject_name = Subjects::model()->findByAttributes(array('id' => $model->subject_id));
                     $examgroup = ExamGroups::model()->findByAttributes(array('id' => $model->exam_group_id));
                     $batch = Batches::model()->findByAttributes(array('id' => $examgroup->batch_id));
                     $exam = ucfirst($subject_name->name) . ' - ' . ucfirst($examgroup->name) . ' (' . ucfirst($batch->name) . '-' . ucfirst($batch->course123->course_name) . ')';
                     //Adding activity to feed via saveFeed($initiator_id,$activity_type,$goal_id,$goal_name,$field_name,$initial_field_value,$new_field_value)
                     ActivityFeed::model()->saveFeed(Yii::app()->user->Id, '18', $model->id, $exam, $model->getAttributeLabel($key), $old_model[$key], $value);
                 }
             }
             //END saving to activity feed
             $this->redirect(array('exams/create', 'id' => $_REQUEST['id'], 'exam_group_id' => $_REQUEST['exam_group_id']));
         }
     }
     $this->render('update', array('model' => $model));
 }
 /**
  * Updates a particular model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id the ID of the model to be updated
  */
 public function actionUpdate($id)
 {
     $model = $this->loadModel($id);
     $settings = UserSettings::model()->findByAttributes(array('user_id' => Yii::app()->user->id));
     if ($settings != NULL) {
         $date1 = date($settings->displaydate, strtotime($model->admission_date));
         $date2 = date($settings->displaydate, strtotime($model->date_of_birth));
     }
     $model->admission_date = $date1;
     $model->date_of_birth = $date2;
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Students'])) {
         $old_model = $model->attributes;
         // For activity feed
         $model->attributes = $_POST['Students'];
         if ($model->admission_date) {
             $model->admission_date = date('Y-m-d', strtotime($model->admission_date));
         }
         if ($model->date_of_birth) {
             $model->date_of_birth = date('Y-m-d', strtotime($model->date_of_birth));
         }
         if ($file = CUploadedFile::getInstance($model, 'photo_data')) {
             $model->photo_file_name = $file->name;
             $model->photo_content_type = $file->type;
             $model->photo_file_size = $file->size;
             $model->photo_data = file_get_contents($file->tempName);
         }
         if ($model->save(false)) {
             // Saving to activity feed
             $results = array_diff_assoc($_POST['Students'], $old_model);
             // To get the fields that are modified.
             //print_r($old_model);echo '<br/><br/>';print_r($_POST['Students']);echo '<br/><br/>';print_r($results);echo '<br/><br/>'.count($results);echo '<br/><br/>';
             foreach ($results as $key => $value) {
                 if ($key != 'updated_at') {
                     if ($key == 'batch_id') {
                         $value = Batches::model()->findByAttributes(array('id' => $value));
                         $value = $value->name . '-' . $value->course123->course_name;
                         $old_model_value = Batches::model()->findByAttributes(array('id' => $old_model[$key]));
                         $old_model[$key] = $old_model_value->name . '-' . $old_model_value->course123->course_name;
                     } elseif ($key == 'gender') {
                         if ($value == 'F') {
                             $value = 'Female';
                         } else {
                             $value = 'Male';
                         }
                         if ($old_model[$key] == 'F') {
                             $old_model[$key] = 'Female';
                         } else {
                             $old_model[$key] = 'Male';
                         }
                     } elseif ($key == 'student_category_id') {
                         $value = StudentCategories::model()->findByAttributes(array('id' => $value));
                         $value = $value->name;
                         $old_model_value = StudentCategories::model()->findByAttributes(array('id' => $old_model[$key]));
                         $old_model[$key] = $old_model_value->name;
                     } elseif ($key == 'nationality_id' or $key == 'country_id') {
                         $value = Countries::model()->findByAttributes(array('id' => $value));
                         $value = $value->name;
                         $old_model_value = Countries::model()->findByAttributes(array('id' => $old_model[$key]));
                         $old_model[$key] = $old_model_value->name;
                     }
                     //echo $key.'-'.$model->getAttributeLabel($key).'-'.$value.'-'.$old_model[$key].'<br/>';
                     //Adding activity to feed via saveFeed($initiator_id,$activity_type,$goal_id,$goal_name,$field_name,$initial_field_value,$new_field_value)
                     ActivityFeed::model()->saveFeed(Yii::app()->user->Id, '4', $model->id, ucfirst($model->first_name) . ' ' . ucfirst($model->middle_name) . ' ' . ucfirst($model->last_name), $model->getAttributeLabel($key), $old_model[$key], $value);
                 }
             }
             //END saving to activity feed
             if (defined('EMAIL_ALERT_ADDRESS')) {
                 $name = $model->first_name . " " . $model->last_name;
                 UserModule::sendMail(constant('EMAIL_ALERT_ADDRESS'), UserModule::t("Student details modified : {student_name}", array('{student_name}' => $name)), UserModule::t("Student details has been modified for : {student_name}", array('{student_name}' => $name)));
             }
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('update', array('model' => $model));
 }