public function actionSaveSelProd()
 {
     if (Yii::app()->session['edit_1st_pdf'] == getCurCusId()) {
         //            echo "ete";exit;
         $this->removeSelectedPoduct(Yii::app()->session['sel_prod']);
     }
     if (count(Yii::app()->session['sel_prod'])) {
         foreach (Yii::app()->session['sel_prod'] as $product) {
             $selPro = SelProducts::model()->findByAttributes(array('product_id' => intval($product), 'cus_id' => intval(getCurCusId())));
             if (!$selPro) {
                 $selPro = new SelProducts();
             }
             $selPro->product_id = intval($product);
             $selPro->cus_id = intval(getCurCusId());
             $selPro->save();
         }
     }
     unset(Yii::app()->session['sel_prod']);
     $this->redirect(array('customer/CustomerQuest'));
 }
 /**
  * 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 $id the ID of the model to be loaded
  * @return SelProducts the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = SelProducts::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
 public function actionAdminSolns1()
 {
     if (isset($_GET['id'])) {
         $id = intval($_GET['id']);
         $curUser = Customer::model()->findByPk($id);
         if (empty($curUser->id)) {
             throw new CHttpException(403, 'Customer Does\'t exists');
         }
         Yii::app()->session['last_created_user'] = $curUser->attributes;
     }
     $cust = Customer::model()->findAll(array('condition' => 'id=:id ', 'params' => array(':id' => getCurCusId())));
     $selProd = SelProducts::model()->findAll(array("condition" => "cus_id =" . getCurCusId(), "order" => "product_id asc"));
     $selData = CHtml::listData($selProd, 'id', 'product_id');
     $criteria = new CDbCriteria();
     $criteria->addInCondition('id', $selData);
     $selproducts = Product::model()->findAll($criteria);
     foreach ($cust as $k => $val) {
         $magicSpools = $val->magicSpools;
         $magicSpoolsAns = $val->magicSpoolsAns;
         $notes = $val->notes;
         $workingWells = $val->workingWells;
         $hotFoods = $val->hotFoods;
         $lunches = $val->lunches;
         $breakfasts = $val->breakfasts;
         $sundries = $val->sundries;
         $indusFoods = $val->indusFoods;
         $sandwiches = $val->sandwiches;
     }
     if (isset($_POST['ajax']) && $_POST['ajax'] == 1) {
         $cust[0]->unable_to_commit = $_POST['final_comment'];
         $cust[0]->save();
         if (count($magicSpools)) {
             $mspoon = MagicSpoolAns::model()->findByAttributes(array('cus_id' => getCurCusId()));
             if ($mspoon === NULL) {
                 $mspoon = new MagicSpoolAns();
                 $mspoon->cus_id = getCurCusId();
             }
             $mspoon->one = isset($_POST['one']) ? $_POST['one'] : "";
             $mspoon->two = isset($_POST['two']) ? $_POST['two'] : "";
             $mspoon->three = isset($_POST['three']) ? $_POST['three'] : "";
             $mspoon->four = isset($_POST['four']) ? $_POST['four'] : "";
             $mspoon->five = isset($_POST['five']) ? $_POST['five'] : "";
             $mspoon->one_comment = isset($_POST['magicspools']['one']['comment']) ? $_POST['magicspools']['one']['comment'] : "";
             $mspoon->two_comment = isset($_POST['magicspools']['two']['comment']) ? $_POST['magicspools']['two']['comment'] : "";
             $mspoon->three_comment = isset($_POST['magicspools']['three']['comment']) ? $_POST['magicspools']['three']['comment'] : "";
             $mspoon->four_comment = isset($_POST['magicspools']['four']['comment']) ? $_POST['magicspools']['four']['comment'] : "";
             $mspoon->five_comment = isset($_POST['magicspools']['five']['comment']) ? $_POST['magicspools']['five']['comment'] : "";
             $mspoon->one_like = isset($_POST['magicspools']['one']['like']) ? intval($_POST['magicspools']['one']['like']) : "0";
             $mspoon->two_like = isset($_POST['magicspools']['two']['like']) ? intval($_POST['magicspools']['two']['like']) : "0";
             $mspoon->three_like = isset($_POST['magicspools']['three']['like']) ? intval($_POST['magicspools']['three']['like']) : "0";
             $mspoon->four_like = isset($_POST['magicspools']['four']['like']) ? intval($_POST['magicspools']['four']['like']) : "0";
             $mspoon->five_like = isset($_POST['magicspools']['five']['like']) ? intval($_POST['magicspools']['five']['like']) : "0";
             //                p($_POST['magicspools']);
             //                exit;
             $mspoon->save();
         }
         if (isset($_POST['hotFoods'])) {
             if (isset($_POST['hotFoods']['ans'])) {
                 foreach ($_POST['hotFoods']['ans'] as $ans) {
                     //                        p($ans);
                     $model = HotFood::model()->findByPk(intval($ans['pro']));
                     $model->ans = $ans['comment'];
                     $model->menu_name = $ans['menuname'];
                     $model->price_per_head_f = $ans['price_per_head_pound'];
                     $model->whats_included = $ans['whats_included'];
                     if (isset($ans['like'])) {
                         $model->like = $ans['like'];
                     }
                     if (isset($ans['cus_comment'])) {
                         $model->comment = $ans['cus_comment'];
                     }
                     $model->save();
                 }
             }
         }
         if (isset($_POST['sandwiches'])) {
             if (isset($_POST['sandwiches']['ans'])) {
                 foreach ($_POST['sandwiches']['ans'] as $ans) {
                     $model = Sandwiches::model()->findByPk(intval($ans['pro']));
                     $model->ans = $ans['comment'];
                     $model->menu_name = $ans['menuname'];
                     $model->price_per_head_f = $ans['price_per_head_pound'];
                     $model->whats_included = $ans['whats_included'];
                     if (isset($ans['like'])) {
                         $model->like = $ans['like'];
                     }
                     if (isset($ans['cus_comment'])) {
                         $model->comment = $ans['cus_comment'];
                     }
                     $model->save();
                 }
             }
         }
         if (isset($_POST['breakfasts'])) {
             if (isset($_POST['breakfasts']['ans'])) {
                 foreach ($_POST['breakfasts']['ans'] as $ans) {
                     $model = Breakfast::model()->findByPk(intval($ans['pro']));
                     $model->ans = $ans['comment'];
                     $model->menu_name = $ans['menuname'];
                     $model->price_per_head_f = $ans['price_per_head_pound'];
                     $model->whats_included = $ans['whats_included'];
                     if (isset($ans['like'])) {
                         $model->like = $ans['like'];
                     }
                     if (isset($ans['cus_comment'])) {
                         $model->comment = $ans['cus_comment'];
                     }
                     //                        p($model->attributes);
                     $model->save();
                 }
             }
         }
         if (isset($_POST['indusFoods'])) {
             if (isset($_POST['indusFoods']['ans'])) {
                 foreach ($_POST['indusFoods']['ans'] as $ans) {
                     $model = IndusFood::model()->findByPk(intval($ans['pro']));
                     $model->ans = $ans['comment'];
                     $model->menu_name = $ans['menuname'];
                     $model->price_per_head_f = $ans['price_per_head_pound'];
                     $model->whats_included = $ans['whats_included'];
                     if (isset($ans['like'])) {
                         $model->like = $ans['like'];
                     }
                     if (isset($ans['cus_comment'])) {
                         $model->comment = $ans['cus_comment'];
                     }
                     $model->save();
                 }
             }
         }
         if (isset($_POST['lunch'])) {
             if (isset($_POST['lunch']['ans'])) {
                 foreach ($_POST['lunch']['ans'] as $ans) {
                     $model = Lunch::model()->findByPk(intval($ans['pro']));
                     $model->ans = $ans['comment'];
                     $model->menu_name = $ans['menuname'];
                     $model->price_per_head_f = $ans['price_per_head_pound'];
                     $model->whats_included = $ans['whats_included'];
                     if (isset($ans['like'])) {
                         $model->like = $ans['like'];
                     }
                     if (isset($ans['cus_comment'])) {
                         $model->comment = $ans['cus_comment'];
                     }
                     //                        p($model->attributes);
                     $model->save();
                 }
             }
         }
         if (isset($_POST['sundries'])) {
             //                $model = Sundries::model()->findByPk($sundries[0]->id);
             //                if ($model !== null) {
             //                    $model->ans = (isset($_POST['sundries']['ans']) ? $_POST['sundries']['ans'] : "");
             //                    $model->comment = (isset($_POST['sundries']['comment']) ? $_POST['sundries']['comment'] : "");
             //                    $model->save();
             //                }
             if (isset($_POST['sundries']['ans'])) {
                 foreach ($_POST['sundries']['ans'] as $ans) {
                     $model = Sundries::model()->findByPk(intval($ans['pro']));
                     $model->ans = $ans['comment'];
                     $model->menu_name = $ans['menuname'];
                     $model->price_per_head_f = $ans['price_per_head_pound'];
                     $model->whats_included = $ans['whats_included'];
                     if (isset($ans['like'])) {
                         $model->like = $ans['like'];
                     }
                     if (isset($ans['cus_comment'])) {
                         $model->comment = $ans['cus_comment'];
                     }
                     $model->save();
                 }
             }
         }
         if (isset($_POST['selproduct']['ans'])) {
             foreach ($_POST['selproduct']['ans'] as $ans) {
                 $selProd = SelProducts::model()->findByPk($ans['pro']);
                 if ($selProd) {
                     $selProd->menu_name = $ans['menuname'];
                     $selProd->price_per_head_f = $ans['price_per_head_pound'];
                     $selProd->ans = $ans['comment'];
                     $selProd->whats_included = $ans['whats_included'];
                     $selProd->save();
                 }
             }
         }
         if (isset($_POST['selprod'])) {
             foreach ($_POST['selprod'] as $comment) {
                 $selProd = SelProducts::model()->findByPk(intval($comment['id']));
                 $selProd->comment = $comment['comment'];
                 $selProd->like = $comment['like'];
                 $selProd->save();
             }
         }
         echo json_encode(array('success' => '1'));
         exit;
     }
     $lunch_note = "";
     $breakfast_note = "";
     $sandwiches_note = "";
     $hotfood_note = "";
     $indusfood_note = "";
     $sundries_note = "";
     //        e($notes);
     foreach ($notes as $value => $kval) {
         //            print_r($kval);
         if ($kval['form'] == 'lunch') {
             $lunch_note = $kval['text'];
         }
         if ($kval['form'] == 'breakfast') {
             $breakfast_note = $kval['text'];
         }
         if ($kval['form'] == 'sandwiches') {
             $sandwiches_note = $kval['text'];
         }
         if ($kval['form'] == 'hotfood') {
             $hotfood_note = $kval['text'];
         }
         if ($kval['form'] == 'indusfood') {
             $indusfood_note = $kval['text'];
         }
         if ($kval['form'] == "sundries") {
             $sundries_note = $kval['text'];
         }
         if ($kval['form'] == 'magicspoon') {
             $mspoon_note = $kval['text'];
         }
     }
     $this->render('adminsolns_pdf', array('customer' => $cust, 'magic_spools' => $magicSpools, 'magicSpoolsAns' => $magicSpoolsAns, 'notes' => $notes, 'workingWells' => $workingWells, 'sundries' => $sundries, 'lunches' => $lunches, 'indusFoods' => $indusFoods, 'breakfasts' => $breakfasts, 'sandwiches' => $sandwiches, 'hotFoods' => $hotFoods, 'sundries_note' => $sundries_note, 'lunch_note' => $lunch_note, 'indusfood_note' => $indusfood_note, 'breakfast_note' => $breakfast_note, 'sandwiches_note' => $sandwiches_note, 'hotfood_note' => $hotfood_note, 'selproducts' => $selproducts, 'selproductsComment' => $selProd));
 }