示例#1
0
 function editworkAction()
 {
     if ($this->isLoggedIn() == 0) {
         $this->_redirect('/admin/index');
     }
     $this->view->langId = $this->_request->getParam('langId');
     $this->view->workId = $this->_request->getParam('workId');
     $fitnessWorkouts = new FitnessWorkouts();
     $fitnessWorkoutsMulti = new FitnessWorkoutsMultilang();
     $fitnessExercises = new FitnessExerciseGeneral();
     $fitnessExercisesMulti = new FitnessExerciseGeneralMultilang();
     $fitnessTimeframes = new FitnessWorkoutTimeframes();
     $workoutDocuments = new FitnessExerciseDocuments();
     $workoutDocumentsMulti = new FitnessExerciseDocumentsMultilang();
     $fitnessDevices = new AppleDevices();
     $fitnessKeys = new FitnessAndroidKey();
     $adminData = new FitnessAdminAccounts();
     $sess = new Zend_Session_Namespace('AdminSession');
     $adminType = $adminData->getTypeByUsername($sess->username);
     $this->view->adminType = $adminType['admin_user_type'];
     $listExercises = $fitnessExercises->selectRecordsWorkout();
     $exerciseArray = array();
     $i = 0;
     foreach ($listExercises as $exercise) {
         $exerciseArray[$i]["exercise_id"] = $exercise['workout_id'];
         $exerciseNameArray = $fitnessExercisesMulti->getWorkoutName($exercise['workout_id'], $this->getDefaultLanguage());
         $exerciseArray[$i]["exercise_name"] = $exerciseNameArray['workout_name'];
         $i = $i + 1;
     }
     $exerciseArray = $this->array_sort_by_column($exerciseArray, 'exercise_name');
     $this->view->listExercises = $exerciseArray;
     $this->view->listtimeframes = $fitnessTimeframes->listTimeframes();
     $this->view->workData = $fitnessWorkouts->getWorkout($this->_request->getParam('workId'));
     $exerciseArray = explode(",", $this->view->workData['work_exercises']);
     $this->view->exercises = $exerciseArray;
     //$this->view->workoutDocuments       = $workoutDocumentsData;
     //$this->view->workoutDocumentsMulti  = $workoutDocumentsMultiData;
     if ($this->_request->getParam('langId') != "") {
         $workmultiData = $fitnessWorkoutsMulti->getWorks($this->_request->getParam('workId'), $this->_request->getParam('langId'));
         if ($this->_request->getParam('langId') == 1) {
             $this->view->workmultiDataTranslate = $fitnessWorkoutsMulti->getWorks($this->_request->getParam('workId'), 2);
         }
         $this->view->workmulti = $workmultiData;
         $this->view->workname = $workmultiData['work_name'];
     } else {
         $workmultiData = $fitnessWorkoutsMulti->getWorks($this->_request->getParam('workId'), $this->getDefaultLanguage());
         $this->view->workmulti = $workmultiData;
         $this->view->workname = $this->view->workData['work_name'];
     }
     $this->view->exercises = explode(",", $this->view->workData['work_exercises']);
     $d = 0;
     foreach ($this->view->exercises as $exerciseID) {
         $exerciseDetails = $fitnessExercisesMulti->getWorkoutName($exerciseID, $this->getDefaultLanguage());
         $sortExerciseArray[$d]['name'] = $exerciseDetails['workout_name'];
         $sortExerciseArray[$d]['id'] = $exerciseID;
         $d = $d + 1;
     }
     if ($this->view->workData['work_exercises_order'] != "") {
         $this->view->sortcomplete = explode(",", $this->view->workData['work_exercises_order']);
         $sortDiff = array_diff($this->view->exercises, $this->view->sortcomplete);
         $reversesortDiff = array_diff($this->view->sortcomplete, $this->view->exercises);
         //print_r($this->view->exercises);echo "<br/>";
         //print_r($this->view->sortcomplete);echo "<br/>";
         //remove deleted exercises
         foreach ($this->view->sortcomplete as $key => $exerciseID) {
             if (in_array($exerciseID, $reversesortDiff)) {
                 unset($this->view->sortcomplete[$key]);
             }
         }
         $j = 0;
         foreach ($this->view->sortcomplete as $exerciseID) {
             $exerciseDetails = $fitnessExercisesMulti->getWorkoutName($exerciseID, $this->getDefaultLanguage());
             $sortCompleteExerciseArray[$j]['name'] = $exerciseDetails['workout_name'];
             $sortCompleteExerciseArray[$j]['id'] = $exerciseID;
             $j = $j + 1;
         }
     }
     $r = 0;
     foreach ($sortDiff as $diff) {
         $exerciseDiffDetails = $fitnessExercisesMulti->getWorkoutName($diff, $this->getDefaultLanguage());
         $sortDiffExerciseArray[$r]['name'] = $exerciseDiffDetails['workout_name'];
         $sortDiffExerciseArray[$r]['id'] = $diff;
         $r = $r + 1;
     }
     $this->view->sortExercises = $sortExerciseArray;
     $this->view->sortCompleteExercises = $sortCompleteExerciseArray;
     $this->view->sortDiffExercises = $sortDiffExerciseArray;
     $workArray = array();
     $workMultiArray = array();
     if ($this->_request->isPost()) {
         $workId = $this->_request->getPost('work_id');
         if ($this->_request->getPost('langId') == "") {
             //$workImage                      = $_FILES["work_image"]["name"];
             $workArray['work_name'] = $this->_request->getPost('work_name');
             $workArray['work_image_list'] = $this->_request->getPost('work_image');
             $workArray['work_exercises'] = rtrim($this->_request->getPost("exerciseslist", ","));
             $workArray['work_duration'] = $this->_request->getPost('work_duration');
             $workArray['work_recovery_time'] = $this->_request->getPost('work_recovery_time');
             $workArray['work_recovery_interval'] = $this->_request->getPost('work_recovery_interval');
             $workArray['work_filter'] = rtrim($this->_request->getPost("filterlist"), ",");
             $workArray['description_small'] = $this->_request->getPost("description_small");
             $workArray['description_big'] = $this->_request->getPost("description_big");
             $workArray['work_level'] = $this->_request->getPost('work_level');
             if ($this->_request->getPost('activestatus') != "") {
                 $workArray['isactive'] = $this->_request->getPost('activestatus');
             }
             if ($this->_request->getPost('isfree') != "") {
                 $workArray['status'] = $this->_request->getPost('isfree');
             }
             $where = "id='" . $workId . "'";
             $fitnessWorkouts->update($workArray, $where);
             /*if($workImage!="")
             	    {
             	    move_uploaded_file($_FILES['work_image']['tmp_name'],'./public/images/exercises/'.$workImage);
             	    $this->createThumb('./public/images/exercises/'.$workImage,'./public/images/exercises/thumbs/'.$workImage,100);
             		$this->createThumbMobile('./public/images/exercises/'.$workImage,'./public/images/exercises/thumbs/mobile/'.$workImage,100);
             	    
             	    }*/
             if ($this->_request->getPost('isactive') == 1) {
                 //update the workout change table
                 $fitnessUpdateChange = new FitnessWorkoutChanges();
                 $changeArray = array();
                 //check if record exists for today's date
                 $currentDate = date('Y-m-d');
                 $checkRecord = $fitnessUpdateChange->getRecordByDate($currentDate);
                 if ($checkRecord['count'] < 1) {
                     $changeArray['status'] = 1;
                     $changeArray['change_date'] = $currentDate;
                     $fitnessUpdateChange->addData($changeArray);
                 }
                 /*$devices      =  $fitnessDevices->getAllDevices();
                 		
                 							$keys         =  $fitnessKeys->getAllKeys();
                 							
                 							$message      =  "The workout ".$this->_request->getPost('work_name')." has been updated in Fitness4.me";
                 							foreach($devices as $device)
                 							{
                 							    if($device['devicetoken'] !="")
                 								{
                 									//$this->sendNotification('lekha',$message,$device['devicetoken'],4);
                 								}
                 								
                 							}
                 							
                 							foreach($keys as $key)
                 							{
                 							    if($key['android_key'] !="")
                 								{
                 									//$this->sentandroid($key['android_key'],$message,4);
                 									
                 								}
                 								
                 								
                 							}*/
             }
         }
         if ($this->_request->getPost('langId') != "") {
             $checkRecords = $fitnessWorkoutsMulti->getLangRecord($this->_request->getPost('work_id'), $this->_request->getPost('langId'));
             $workMultiArray['work_id'] = $workId;
             $workMultiArray['lang_id'] = $this->_request->getPost('langId');
             $workMultiArray['work_name'] = $this->_request->getPost('work_name');
             $workMultiArray['description_small'] = $this->_request->getPost("description_small");
             $workMultiArray['description_big'] = $this->_request->getPost("description_big");
             if ($checkRecords['count'] > 0) {
                 $fitnessWorkoutsMulti->update($workMultiArray, array('work_id = ?' => $this->_request->getPost('work_id'), 'lang_id = ?' => $this->_request->getPost('langId')));
             } else {
                 $fitnessWorkoutsMulti->addData($workMultiArray);
             }
         }
         $this->_redirect('/admin/listworks');
     }
 }