Example #1
0
 /**
  * Method addRowLoadFromSqlDataView
  * @access private
  * @param mixed $row 
  * @param mixed $list_attribute 
  * @param mixed $list_attribute_type 
  * @param mixed $key_attributes 
  * @param mixed $ind 
  * @param boolean $is_delete_action [default value: false]
  * @param double $line_nb [default value: 0]
  * @return boolean
  * @since 1.1.6
  */
 private function addRowLoadFromSqlDataView($row, $list_attribute, $list_attribute_type, $key_attributes, $ind, $is_delete_action = false, $line_nb = null)
 {
     if ($this->from_sql_data_view_delete) {
         // create delete button if not already exists
         $bnt_del_id = $this->id . "_btndel__ind_" . $ind;
         $delete_pic = $this->getPage()->getObjectId($bnt_del_id);
         if ($delete_pic == null) {
             $delete_pic = new Picture("img/wsp-admin/delete_16.png", 16, 16, 0, Picture::ALIGN_ABSMIDDLE);
             $delete_pic->setId($bnt_del_id);
             $delete_pic->onClickJs("if (!confirm('" . __(TABLE_CONFIME_DEL_ROW) . "')) { return false; }");
             $delete_pic->onClick($this->getPage(), "onChangeTableFromSqlDataView")->setAjaxEvent()->disableAjaxWaitMessage();
         }
     }
     // create row
     $row_table = new RowTable();
     $row_table->setId($this->id . "_row_" . $ind);
     for ($i = 0; $i < sizeof($list_attribute); $i++) {
         // get field properties
         if (is_array($this->from_sql_data_view_properties[$list_attribute[$i]])) {
             $attribute_properties = $this->from_sql_data_view_properties[$list_attribute[$i]];
         } else {
             $attribute_properties = array();
         }
         // get property display
         if (isset($attribute_properties["display"]) && $attribute_properties["display"] == false) {
             continue;
         }
         // get property update
         $is_update_ok = true;
         if (isset($attribute_properties["update"]) && $attribute_properties["update"] == false) {
             $is_update_ok = false;
         }
         if ($this->from_sql_data_view_update && !in_array($list_attribute[$i], $key_attributes) && $is_update_ok) {
             $row_value = $row->getValue($list_attribute[$i]);
             if (gettype($row_value) == "object" && method_exists($row_value, "render")) {
                 $row_value = $row_value->render();
             }
             $edit_pic = new Picture("wsp/img/edit_16x16.png", 16, 16);
             $row_obj = new Object($edit_pic, trim($row_value) == "" ? "&nbsp;&nbsp;" : utf8encode($row_value));
             $row_obj->setId($this->id . "_" . $list_attribute[$i] . "_obj_" . $ind)->setStyle("cursor:pointer;border:1px solid gray;");
             $input_obj = $this->createDbAttributeObject($row, $list_attribute, $list_attribute_type, $i, $ind, $key_attributes);
             if (get_class($input_obj) == "ComboBox") {
                 // Get foreign key value
                 $row_obj->emptyObject();
                 $value = $input_obj->getText();
                 $row_obj->add($edit_pic, trim($value) == "" ? "&nbsp;&nbsp;" : $value);
             } else {
                 if (get_class($input_obj) == "Calendar") {
                     $row_obj->emptyObject();
                     $value = $input_obj->getValueStr();
                     $row_obj->add($edit_pic, trim($value) == "" ? "&nbsp;&nbsp;" : $value);
                     $row_table->setNowrap();
                 }
             }
             $row_obj_input = new Object($input_obj);
             $row_obj_input->setId($this->id . "_" . $list_attribute[$i] . "_input_obj_" . $ind);
             $cancel_pic = new Picture("wsp/img/cancel_12x12.png", 12, 12);
             $cancel_pic->setId($this->id . "_img_" . $ind . "_cancel_" . $list_attribute[$i]);
             $cancel_pic->onClickJs("\$('#" . $row_obj->getId() . "').css('display', 'inline');\$('#" . $row_obj_input->getId() . "').hide();" . ($this->from_sql_data_view_add_button != null ? "\$('#" . $this->from_sql_data_view_add_button->getId() . "').button({ disabled: false });" : ""));
             $cancel_pic_obj = new Object($cancel_pic);
             $row_obj_input->add($cancel_pic_obj->forceSpanTag()->setStyle("position:absolute;"));
             if (!$this->getPage()->isAjaxPage() || $is_delete_action || $this->from_sql_data_view_reload_pic != null && $this->from_sql_data_view_reload_pic->isClicked() || $this->from_sql_data_view_add_button != null && $this->from_sql_data_view_add_button->isClicked()) {
                 $this->getPage()->addObject(new JavaScript("\$(document).ready(function() { \$('#" . $row_obj_input->getId() . "').hide(); });"));
             }
             $row_obj->onClickJs("\$('#" . $row_obj->getId() . "').hide();\$('#" . $row_obj_input->getId() . "').show();" . ($this->from_sql_data_view_add_button != null ? "\$('#" . $this->from_sql_data_view_add_button->getId() . "').button({ disabled: true });" : ""));
             $row_table->add(new Object($row_obj, $row_obj_input));
             // get properties align
             if (isset($attribute_properties["align"])) {
                 $row_table->setColumnAlign($i + 1, $attribute_properties["align"]);
             }
         } else {
             $value = $row->getValue($list_attribute[$i]);
             if (isset($this->from_sql_data_view_properties[$list_attribute[$i]]['cmb_obj'])) {
                 $input_obj_tmp = $this->from_sql_data_view_properties[$list_attribute[$i]]['cmb_obj'];
                 $input_obj_tmp->setValue($value);
                 $value = $input_obj_tmp->getText();
             }
             if (get_class($value) == "DateTime") {
                 $value = $value->format("Y-m-d");
             }
             $row_table->add(utf8encode($value));
         }
     }
     if ($this->from_sql_data_view_delete) {
         $row_table->add($delete_pic);
     } else {
         if ($this->from_sql_data_view_insert) {
             $row_table->add();
         }
     }
     if ($is_table_defined_style) {
         $row_table->setBorderPredefinedStyle($this->class);
     }
     if ($this->is_advance_table) {
         if (isset($line_nb) && $line_nb !== null) {
             $row_table->setRowClass($line_nb % 2 == 0 ? "odd" : "even");
         } else {
             if (is_numeric($ind)) {
                 $row_table->setRowClass($ind % 2 == 0 ? "odd" : "even");
             } else {
                 $row_table->setRowClass("even");
             }
         }
     }
     $this->addRow($row_table);
 }