コード例 #1
0
 public function doAddJobFunctionAction()
 {
     $this->_helper->layout->disableLayout();
     $this->_helper->viewRenderer->setNoRender();
     $user = PR_Session::getSession(PR_Session::SESSION_USER);
     $ajaxRes = array('success' => 0, 'info' => null, 'pecent' => null);
     if ($this->getRequest()->isXmlHttpRequest()) {
         $params = $this->getRequest()->getParams();
         //echo "testt:<pre>";print_r($params);echo("</pre>");die();
         $JobFucntion = null;
         $CredentialExperienceID = null;
         $Percentage = null;
         $pecent = 0;
         $Percentage1 = 0;
         $Text = array("JobFucntion1" => "");
         if (!empty($params['data']) && sizeof($params['data'])) {
             foreach ($params['data'] as $key => $item) {
                 if ($item['name'] == 'empId') {
                     $empId = $item['value'];
                 }
                 if ($item['name'] == 'JobFucntion_add') {
                     $JobFucntion = $item['value'];
                 }
                 //if($item['name']=='JobFucntion1[]')      $JobFucntion1 = $item['value'];
                 if ($item['name'] == 'Percentage_add') {
                     $Percentage = $item['value'];
                 }
                 if ($item['name'] == 'Percentage1[]') {
                     $Percentage1 = $item['value'] + $Percentage1;
                 }
                 if ($item['name'] == 'JobFucntion1[]') {
                     $Text["JobFucntion1"][] = $item['value'];
                 }
             }
             if ($Percentage == "") {
                 $ajaxRes['success'] = 0;
                 $ajaxRes['info'] = "Percentage not empty";
             }
             if ($JobFucntion == "") {
                 $ajaxRes['success'] = 0;
                 $ajaxRes['info'] = "Job Fucntion not empty";
             }
             if (!is_numeric($Percentage)) {
                 $ajaxRes['success'] = 0;
                 $ajaxRes['info'] = "Percentage must be integer";
             }
             $selectarray = array();
             if (!empty($Text["JobFucntion1"])) {
                 foreach ($Text["JobFucntion1"] as $Values) {
                     $selectarray[] = $Values;
                 }
             }
             $core = new PR_Api_Core_CandidateClass();
             $jobdb = $core->get_jobfuntion($empId);
             $jobaray = array();
             if (!empty($jobdb)) {
                 foreach ($jobdb as $job) {
                     $jobaray[] = $job["JobFunctionID"];
                 }
             }
             if (in_array($JobFucntion, $selectarray) || in_array($JobFucntion, $jobaray)) {
                 $ajaxRes['success'] = 0;
                 $ajaxRes['info'] = "Job Fucntion is exit.";
             }
             //print_r($selectarray);
             //if(empty($JobFucntion)) $errors['JobFucntion'] = 1;
             $pecent = $Percentage + $pecent + $Percentage1;
             //echo "tetst:".$pecent;
             if ($Percentage != "" && $JobFucntion != "") {
                 $client = PR_Session::getSession(PR_Session::SESSION_USER);
                 $totalPercentage = $core->totalPercentage($empId);
                 $totalPercentage = round($totalPercentage["totalPercentage"], 2);
                 //$Percentage=($Percentage/100);
                 $pecent = $pecent / 100;
                 $total = $totalPercentage + $pecent;
                 // echo "tetst:<pre>";print_r($total);echo("</pre>");die();
                 if ($total > 1) {
                     $ajaxRes['success'] = 0;
                     $ajaxRes['info'] = "Total Percentage greater than 100%";
                 } else {
                     $ajaxRes['success'] = 1;
                     $ajaxRes['pecent'] = $total;
                 }
             } else {
                 // $ajaxRes['info'] = $errors;
             }
         }
     }
     $response = $this->getResponse();
     $response->clearAllHeaders()->clearBody();
     $ajaxRes = json_encode($ajaxRes);
     $response->setHeader('Content-type', 'application/json');
     $response->setHeader('Content-Length', strlen($ajaxRes), true)->setBody($ajaxRes);
 }