public function _initialize() { parent::_initialize(); //各页面下拉选项列表 $school_year_options = D('SchoolYear')->getOptions($this->school_year); $town_id_options = get_town_options($this->town_id); $school_code_options = get_school_options($this->school_year, $this->town_id, $this->school_code); $this->assign('school_year_options', $school_year_options); $this->assign('town_id_options', $town_id_options); $this->assign('school_code_options', $school_code_options); //判断是否需要为模版年级和班级下拉框赋值 if (in_array(ACTION_NAME, array('template', 'receipt', 'cshedu')) && !IS_AJAX) { $school_grade_options = get_grade_options($this->school_year, $this->town_id, $this->school_code, $this->school_grade, 'school_code'); $class_num_options = get_class_options($this->school_year, $this->town_id, $this->school_code, $this->school_grade, $this->class_num); $this->assign('school_grade_options', $school_grade_options); $this->assign('class_num_options', $class_num_options); } }
function get_class_options($upid, $found) { global $pro_class_table; global $sys_product_level; //產品架最大層數 $table = $pro_class_table; $sql = "select * from `{$table}` where `upid`={$upid} order by no DESC,id ASC"; $res = mysql_query($sql); while ($row = mysql_fetch_array($res)) { $history = explode(';', $row['history']); $level = count($history) + 1; if ($level + 1 < $sys_product_level) { echo '<optgroup label="'; for ($i = 0; $i < $level * 3; $i++) { echo " "; } echo $row['name'] . '">'; get_class_options($row['id'], $found); echo '</optgroup>'; } else { if ($found != $row['id']) { echo "<option value='" . $row['id'] . "' >"; for ($i = 0; $i < $level * 3; $i++) { echo " "; } echo $row['name'] . "</option>"; } else { echo "<option value='" . $row['id'] . "' selected>"; for ($i = 0; $i < $level * 3; $i++) { echo " "; } echo $row['name'] . "</option>"; } } } }
private function ajaxSelect() { $selectType = I('select_type', ''); if ($selectType == '' || !in_array($selectType, array('school', 'grade', 'class'))) { $this->ajaxReturn(array('errno' => 1, 'errtitle' => '参数错误!')); } $options = ''; switch ($selectType) { case 'school': $options = get_school_options($this->school_year, $this->town_id, $this->school_code); break; case 'grade': $options = get_grade_options($this->school_year, $this->town_id, $this->school_code, $this->school_grade); break; case 'class': $options = get_class_options($this->school_year, $this->town_id, $this->school_code, $this->school_grade, $this->class_num); break; } $this->ajaxReturn(array('errno' => 0, 'optionstr' => $options)); }