コード例 #1
0
ファイル: equipment.ajax.php プロジェクト: suxinde2009/www
 /**
  * @param string $get_array
  * @param string $type_array
  * @param string $category_array
  * @return string
  */
 public static function add_as_item_window($get_array, $type_array, $category_array)
 {
     if ($get_array) {
         $_GET = unserialize($get_array);
     }
     if ($type_array) {
         $type_array = unserialize($type_array);
     }
     if ($category_array) {
         $category_array = unserialize($category_array);
     }
     $template = new HTMLTemplate("equipment/add_item_window.html");
     $equipment_array = EquipmentType::list_entries();
     $result = array();
     $hit_array = array();
     $counter = 0;
     if (is_array($type_array) and count($type_array) >= 1) {
         if (is_array($equipment_array) and count($equipment_array) >= 1) {
             foreach ($equipment_array as $key => $value) {
                 if (in_array($value, $type_array) or $value <= 3) {
                     $equipment_type = new EquipmentType($value);
                     $result[$counter]['value'] = $value;
                     $result[$counter]['disabled'] = "";
                     $result[$counter]['content'] = $equipment_type->get_name() . " (" . $equipment_type->get_cat_name() . ")";
                     $counter++;
                     array_push($hit_array, $value);
                 }
             }
         }
         if (is_array($category_array) and count($category_array) >= 1) {
             foreach ($category_array as $key => $value) {
                 $equipment_cat_array = EquipmentType::list_entries_by_cat_id($value);
                 if (is_array($equipment_cat_array) and count($equipment_cat_array) >= 1) {
                     foreach ($equipment_cat_array as $key => $value) {
                         if (!in_array($value, $hit_array)) {
                             $equipment_type = new EquipmentType($value);
                             $result[$counter]['value'] = $value;
                             $result[$counter]['disabled'] = "";
                             $result[$counter]['content'] = $equipment_type->get_name() . " (" . $equipment_type->get_cat_name() . ")";
                             $counter++;
                             array_push($hit_array, $value);
                         }
                     }
                 }
             }
         }
     } else {
         if (is_array($category_array) and count($category_array) >= 1) {
             foreach ($category_array as $key => $value) {
                 $equipment_cat_array = EquipmentType::list_entries_by_cat_id($value);
                 if (is_array($equipment_cat_array) and count($equipment_cat_array) >= 1) {
                     if (!in_array(1, $equipment_cat_array)) {
                         $equipment_cat_array[] = 1;
                     }
                     if (!in_array(2, $equipment_cat_array)) {
                         $equipment_cat_array[] = 2;
                     }
                     if (!in_array(3, $equipment_cat_array)) {
                         $equipment_cat_array[] = 3;
                     }
                     foreach ($equipment_cat_array as $key => $value) {
                         if (!in_array($value, $hit_array)) {
                             $equipment_type = new EquipmentType($value);
                             $result[$counter]['value'] = $value;
                             $result[$counter]['disabled'] = "";
                             $result[$counter]['content'] = $equipment_type->get_name() . " (" . $equipment_type->get_cat_name() . ")";
                             $counter++;
                             array_push($hit_array, $value);
                         }
                     }
                 }
             }
         } else {
             if (is_array($equipment_array) and count($equipment_array) >= 1) {
                 foreach ($equipment_array as $key => $value) {
                     $equipment_type = new EquipmentType($value);
                     $result[$counter]['value'] = $value;
                     $result[$counter]['disabled'] = "";
                     $result[$counter]['content'] = $equipment_type->get_name() . " (" . $equipment_type->get_cat_name() . ")";
                     $counter++;
                 }
             }
         }
     }
     if ($counter == 0) {
         $result[0]['value'] = "0";
         $result[0]['disabled'] = "disabled='disabled'";
         $result[0]['content'] = "NO EQUIPMENT FOUND!";
     }
     $template->set_var("select", $result);
     if ($_GET['parent'] and is_numeric($_GET['parent_id'])) {
         $array['container'] = "#EquipmentItemAddWindow" . $_GET['parent_key'] . "-" . $_GET['parent_id'] . "-" . $_GET['key'];
         $container_value_select = "EquipmentItemAddValueField" . $_GET['parent_key'] . "-" . $_GET['parent_id'] . "-" . $_GET['key'];
     } else {
         $array['container'] = "#EquipmentItemAddWindow" . $_GET['key'];
         $container_value_select = "EquipmentItemAddValueField" . $_GET['key'];
     }
     $template->set_var("container_value_select_id", $container_value_select);
     $array['continue_caption'] = "Add";
     $array['cancel_caption'] = "Cancel";
     $array['content_caption'] = "Add Equipment";
     $array['height'] = 350;
     $array['width'] = 400;
     $array['content'] = $template->get_string();
     $continue_handler_template = new JSTemplate("equipment/js/add_item_window.js");
     $continue_handler_template->set_var("session_id", $_GET['session_id']);
     $continue_handler_template->set_var("get_array", $get_array);
     $continue_handler_template->set_var("container_id", $array['container']);
     $continue_handler_template->set_var("container_value_select_id", $container_value_select);
     $array['continue_handler'] = $continue_handler_template->get_string();
     return json_encode($array);
 }
コード例 #2
0
 /**
  * @see EquipmentCatInterface::delete()
  * @return bool
  */
 public function delete()
 {
     if ($this->equipment_cat_id and $this->equipment_cat) {
         if ($this->get_children() != null) {
             return false;
         } else {
             $equipment_type_array = EquipmentType::list_entries_by_cat_id($this->equipment_cat_id);
             if (!is_array($equipment_type_array)) {
                 return $this->equipment_cat->delete();
             } else {
                 if (count($equipment_type_array) == 0) {
                     return $this->equipment_cat->delete();
                 } else {
                     return false;
                 }
             }
         }
     } else {
         return false;
     }
 }