protected function jsJobSubCategoryUpdate()
 {
     $output = "";
     /* create the jobCategory <-> jobSubCategory connection */
     $output .= "var jobSubCategoryNames = new Array();\n";
     $output .= "var jobSubCategoryIds = new Array();\n";
     $output .= "jobSubCategoryNames[" . static::anyJobCategoryCode . "] = [\"Select job category first\"];\n";
     $output .= "jobSubCategoryIds[" . static::anyJobCategoryCode . "] = [\"" . static::anyJobSubCategoryCode . "\"];\n";
     $jobCategoryList = JobCategory::getAllRows();
     $jobCategoryCount = 0;
     while (($jobCategory = $jobCategoryList->fetch_row()) != NULL) {
         $jobCategoryId = JobCategory::getJobCategoryId($jobCategory);
         $jobSubCategoryList = JobSubCategory::getJobSubCategoryList($jobCategoryId);
         /* first the jobSubCategory names */
         $output .= "jobSubCategoryNames[{$jobCategoryId}] = [\"Any job sub category\"";
         while (($jobSubCategory = $jobSubCategoryList->fetch_row()) != NULL) {
             $output .= ", \"" . JobSubCategory::getJobSubCategoryName($jobSubCategory) . "\"";
         }
         $output .= "];\n";
         /* then the jobSubCategory Ids */
         $output .= "jobSubCategoryIds[{$jobCategoryId}] = [\"" . static::anyJobSubCategoryCode . "\"";
         $jobSubCategoryList->data_seek(0);
         while (($jobSubCategory = $jobSubCategoryList->fetch_row()) != NULL) {
             $output .= ", \"" . JobSubCategory::getJobSubCategoryId($jobSubCategory) . "\"";
         }
         $output .= "];\n";
     }
     /* print the jobSubCategoryUpdate() function */
     /* the below code is JavaScript */
     $output .= "\n";
     $output .= "jobSubCategoryList = document." . static::formName . "." . static::jobSubCategoryIdFieldName . ";\n";
     $output .= "function jobSubCategoryUpdate(selectedJobCategoryId){\n";
     $output .= " jobSubCategoryList.options.length = 0;\n";
     $output .= " for (i=0; i < jobSubCategoryNames[selectedJobCategoryId].length; i++) {\n";
     $output .= "      jobSubCategoryList.options[jobSubCategoryList.options.length] = new Option(jobSubCategoryNames[selectedJobCategoryId][i],jobSubCategoryIds[selectedJobCategoryId][i]);\n";
     $output .= " }\n";
     $output .= "}\n";
     return $output;
 }
Esempio n. 2
0
 protected function fieldJobCategory($jsAction = "")
 {
     $output = "";
     $allJobCategories = JobCategory::getAllRows();
     $output .= "<select name=\"" . static::jobCategoryIdFieldName . "\" {$jsAction}>\n";
     /* The following logic will determine the selected option */
     /* Chose a do...while() in order to avoid code duplication for the 'selected' option logic */
     /* !!! As this is a copy+paste from the previous function, there should be a code optimisation to it */
     $jobCategoryId = static::anyJobCategoryCode;
     $jobCategoryName = "Any job category";
     $firstRow = true;
     do {
         if (!$firstRow) {
             $jobCategoryId = JobCategory::getJobCategoryId($row);
             $jobCategoryName = JobCategory::getJobCategoryName($row);
         } else {
             $firstRow = false;
         }
         if ($this->searchedJobCategoryId == $jobCategoryId) {
             $selected = "selected";
         } else {
             $selected = "";
         }
         /* here is the actual option output */
         $output .= " <option {$selected} value =\"{$jobCategoryId}\">{$jobCategoryName}</option>\n";
     } while (($row = $allJobCategories->fetch_row()) != NULL);
     $output .= "</select>\n";
     return $output;
 }