Xarx.es

Dèries. La meua llibreta d'anotacions.

Diff Respecto DataGrid 4.20 (II)

Vuelvo a incluir los cambios respecto del datagrid "oficial".

ChangeLog:

1-. eliminar un intval en la opción linktoedit (modo view) que forzaba a que los campos que se usaban como enlaces correspondiesen a una "Primary Key" que fuese un entero. Esto no tiene por que ser cierto (por ejemplo, la clave primaria de la BD de Wview - Estación Meteorológica del Planetari de Castelló - es un datetime)

2-. Cuando se usa una selección múltiple, los elementos seleccionados se concatenan y se separan con ‘-‘. Yo lo he modificado para que se concatenen con ‘_’ pues en el caso anterior de 2 datetimes la separación entre año, mes y día era también ‘-’ por lo que había conflictos y los campos no se identificaban correctamente.

Para ver el código y bajarlo es necesario mostrar el artículo completo…

Los archivos:

1-. Diferencias respecto de la versión modificada anterior:

Diferencias respecto versión modificada anterior (datagrid.class.v2.diff) download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
--- ../../../var/www/pedidos/datagrid/datagrid.class.php    2007-10-25 10:27:56.000000000 +0200
+++ ../../../var/www/mimeteo/datagrid420/datagrid.class.php  2007-11-07 09:57:18.000000000 +0100
@@ -614,6 +614,6 @@ class DataGrid
         $this->multi_rows = 0;
         $this->multirow_operations_array = array();
-        $this->multirow_operations_array['delete'] = array("view"=>true);
-        $this->multirow_operations_array['details'] = array("view"=>true);
+        //$this->multirow_operations_array['delete'] = array("view"=>true);  //FERNANDO: habilitarlos explicitamente
+        //$this->multirow_operations_array['details'] = array("view"=>true);

         $this->first_field_focus_allowed = false;
@@ -1101,5 +1101,6 @@ class DataGrid
             $this->sql_sort = " ORDER BY " . $this->primary_key . " DESC";
             if(($this->layouts['view'] == 0) && ($this->layouts['edit'] == 1) && ($req_mode == "details")){
-                $this->rids = explode("-", $this->rid);
+                //$this->rids = explode("-", $this->rid); //FERNANDO
+        $this->rids = explode("_", $this->rid);
                 // if we have more that 1 row selected
                 if(count($this->rids) > 1){
@@ -1115,5 +1116,6 @@ class DataGrid
                 $this->sql = "SELECT * FROM $this->tbl_name ".$where;
             }else if(($this->layouts['view'] == 0) && ($this->layouts['edit'] == 1) && ($req_mode == "edit")){
-                $this->rids = explode("-", $this->rid);
+                //$this->rids = explode("-", $this->rid); //FERNANDO
+        $this->rids = explode("_", $this->rid);
                 // if we have more that 1 row selected
                 // mr_1
@@ -1131,5 +1133,6 @@ class DataGrid
             }else if(($this->layouts['view'] == 0) && ($this->layouts['edit'] == 0) && ($req_mode == "details")){
                 // if we have more that 1 row selected
-                $this->rids = explode("-", $this->rid);
+                //$this->rids = explode("-", $this->rid); //FERNANDO
+        $this->rids = explode("_", $this->rid);
                 if(count($this->rids) > 1){
                     $where = "WHERE ".$this->primary_key." IN (-1 ";
@@ -2685,5 +2688,6 @@ class DataGrid
                     for(i=".$this->row_lower."; i < ".$this->row_upper."; i++){
                         if(document.getElementById(\"".$this->unique_prefix."checkbox_\"+i).checked == true){
-                            if(found == 1){ selected_rows_ids += '-'; }
+                            //if(found == 1){ selected_rows_ids += '-'; }
+                            if(found == 1){ selected_rows_ids += '_'; }
                             selected_rows_ids += document.getElementById(\"".$this->unique_prefix."checkbox_\"+i).value;
                             found = 1;
@@ -3231,5 +3235,6 @@ class DataGrid
     //--------------------------------------------------------------------------
     function deleteRow($rid){
-        $this->rids = explode("-", $rid);
+        //$this->rids = explode("-", $rid); //FERNANDO
+    $this->rids = explode("_", $this->rid);
         $sql = "DELETE FROM $this->tbl_name WHERE $this->primary_key IN (-1 ";
         foreach ($this->rids as $key){
@@ -4026,5 +4031,7 @@ class DataGrid
                         break;
                     case "linktoview";
-                        $curr_url = $this->combineUrl("details", intval($row[(($this->getFieldOffset($this->primary_key) != -1) ? $this->getFieldOffset($this->primary_key) : 0)]));                         
+            //FERNANDO: Retiro intval porque si la clave no es un entero se jode el invento.
+                        //$curr_url = $this->combineUrl("details", intval($row[(($this->getFieldOffset($this->primary_key) != -1) ? $this->getFieldOffset($this->primary_key) : 0)]));
+                        $curr_url = $this->combineUrl("details", $row[(($this->getFieldOffset($this->primary_key) != -1) ? $this->getFieldOffset($this->primary_key) : 0)]);
                         $this->setUrlStringPaging($curr_url);
                         $this->setUrlStringSorting($curr_url);

2-. Diferencias respecto de la versión oficial 4.20:

Diferencias respecto versión oficial 4.20 (datagrid.class.v2total.diff) download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
--- datagrid420/datagrid.class.php  2007-09-29 04:09:50.000000000 +0200
+++ ../../../var/www/mimeteo/datagrid/datagrid.class.php 2007-11-07 09:57:18.000000000 +0100
@@ -578,5 +578,6 @@ class DataGrid
         $this->modes["edit"]    = array("view"=>true, "edit"=>true, "type"=>"link", "byFieldValue"=>"");
         $this->modes["cancel"]  = array("view"=>true, "edit"=>true, "type"=>"link");
-        $this->modes["details"] = array("view"=>true, "edit"=>false, "type"=>"link");$this->modes["delete"]  = array("view"=>true, "edit"=>true, "type"=>"image");            
+        $this->modes["details"] = array("view"=>true, "edit"=>false, "type"=>"link");
+        $this->modes["delete"]  = array("view"=>true, "edit"=>true, "type"=>"image");

         $this->mode = "view";
@@ -613,6 +614,6 @@ class DataGrid
         $this->multi_rows = 0;
         $this->multirow_operations_array = array();
-        $this->multirow_operations_array['delete'] = array("view"=>true);
-        $this->multirow_operations_array['details'] = array("view"=>true);
+        //$this->multirow_operations_array['delete'] = array("view"=>true);  //FERNANDO: habilitarlos explicitamente
+        //$this->multirow_operations_array['details'] = array("view"=>true);

         $this->first_field_focus_allowed = false;
@@ -1100,5 +1101,6 @@ class DataGrid
             $this->sql_sort = " ORDER BY " . $this->primary_key . " DESC";
             if(($this->layouts['view'] == 0) && ($this->layouts['edit'] == 1) && ($req_mode == "details")){
-                $this->rids = explode("-", $this->rid);
+                //$this->rids = explode("-", $this->rid); //FERNANDO
+        $this->rids = explode("_", $this->rid);
                 // if we have more that 1 row selected
                 if(count($this->rids) > 1){
@@ -1114,5 +1116,6 @@ class DataGrid
                 $this->sql = "SELECT * FROM $this->tbl_name ".$where;
             }else if(($this->layouts['view'] == 0) && ($this->layouts['edit'] == 1) && ($req_mode == "edit")){
-                $this->rids = explode("-", $this->rid);
+                //$this->rids = explode("-", $this->rid); //FERNANDO
+        $this->rids = explode("_", $this->rid);
                 // if we have more that 1 row selected
                 // mr_1
@@ -1130,5 +1133,6 @@ class DataGrid
             }else if(($this->layouts['view'] == 0) && ($this->layouts['edit'] == 0) && ($req_mode == "details")){
                 // if we have more that 1 row selected
-                $this->rids = explode("-", $this->rid);
+                //$this->rids = explode("-", $this->rid); //FERNANDO
+        $this->rids = explode("_", $this->rid);
                 if(count($this->rids) > 1){
                     $where = "WHERE ".$this->primary_key." IN (-1 ";
@@ -1334,4 +1338,5 @@ class DataGrid
     }

+
     //--------------------------------------------------------------------------
     // set fields for filtering
@@ -1360,7 +1365,11 @@ class DataGrid
                         if(isset($fldValue['case_sensitive']) && ($fldValue['case_sensitive'] != true)){
                             $fldTableField = $this->getLcaseFooByDbType()."(".(($fldValue['table'] != "") ? $fldValue['table']."." : "" ).$fldValue['field'].")";
+                            if(strpos($fldTableField,'_')!==false) 
+                $fldTableField=str_replace("_",".",$fldTableField);
                             $fldTableFieldName = strtolower($_REQUEST[$this->unique_prefix."_ff_".$table_field_name]);
                         }else{
                             $fldTableField = (($fldValue['table'] != "") ? $fldValue['table']."." : "" ).$fldValue['field'];
+                            if(strpos($fldTableField,'_')!==false) 
+                $fldTableField=str_replace("_",".",$fldTableField);
                             $fldTableFieldName = $_REQUEST[$this->unique_prefix."_ff_".$table_field_name];
                         }
@@ -1379,4 +1388,6 @@ class DataGrid
                             }else if($_REQUEST[$this->unique_prefix."_ff_".$filter_field_operator] == "%like"){
                                 $this->sql_view .= " $search_type_start $fldTableField ".substr($_REQUEST[$this->unique_prefix."_ff_".$filter_field_operator], 1, 4)." ".$comparison_type." '%".$fldTableFieldName."'";
+                            }else if($_REQUEST[$this->unique_prefix."_ff_".$filter_field_operator] == "%like%"){
+                                $this->sql_view .= " $search_type_start $fldTableField ".substr($_REQUEST[$this->unique_prefix."_ff_".$filter_field_operator], 1, 4)." ".$comparison_type." '%".$fldTableFieldName."%'";
                             }else{
                                 $this->sql_view .= " $search_type_start $fldTableField ".$_REQUEST[$this->unique_prefix."_ff_".$filter_field_operator]." $left_geresh".$fldTableFieldName."$left_geresh ";
@@ -1774,5 +1785,5 @@ class DataGrid
             fclose($fe);
             echo "<script type='text/javascript'>\n<!--\n "
-            ."if(confirm('Do you want to export datagrid content into export.csv file?')){ "
+            ."if(confirm('".$this->lang['export_to_excel_confirm']."')){ "
             ." document.write('".str_replace("_FILE_", "export.csv", $this->lang['export_message'])."'); "
             ." document.location = '".$this->directory."scripts/download.php?dir=".$this->directory."&file=export.csv'; "
@@ -1825,5 +1836,5 @@ class DataGrid

             echo "<script type='text/javascript'>\n<!--\n "
-            ."if(confirm('Do you want to export datagrid content into export.xml file?')){ "
+            ."if(confirm('".$this->lang['export_to_xml_confirm']."')){ "
             ." document.write('".str_replace("_FILE_", "export.xml", $this->lang['export_message'])."'); "
             ." document.location = '".$this->directory."scripts/download.php?dir=".$this->directory."&file=export.xml'; "
@@ -1898,4 +1909,5 @@ class DataGrid
                         echo "<option value='like%'"; echo ($filter_operator == "like%")? "selected" : ""; echo ">".$this->lang['like%']."</option>";
                         echo "<option value='%like'"; echo ($filter_operator == "%like")? "selected" : ""; echo ">".$this->lang['%like']."</option>";
+                        echo "<option value='%like%'"; echo ($filter_operator == "%like%")? "selected" : ""; echo ">".$this->lang['%like%']."</option>";
                         echo "<option value='not like'"; echo ($filter_operator == "not like")? "selected" : ""; echo ">".$this->lang['not_like']."</option>";
                         echo "</select>";
@@ -2105,5 +2117,5 @@ class DataGrid
                                         else{ $href_string .= "asc"; }
                                     }
-                                    echo "<nobr><b><a class='".$this->unique_prefix."class_a' href='$href_string' title='Sort' ";
+                                    echo "<nobr><b><a class='".$this->unique_prefix."class_a' href='$href_string' title='".$this->lang['sort']."' ";
                                     if($req_sort_field && ($c == ($req_sort_field -1))){
                                         echo "onmouseover=\"if(document.getElementById('soimg".$c."')){ document.getElementById('soimg".$c."').src='".$sort_img_back."';  }\" ";
@@ -2676,5 +2688,6 @@ class DataGrid
                     for(i=".$this->row_lower."; i < ".$this->row_upper."; i++){
                         if(document.getElementById(\"".$this->unique_prefix."checkbox_\"+i).checked == true){
-                            if(found == 1){ selected_rows_ids += '-'; }
+                            //if(found == 1){ selected_rows_ids += '-'; }
+                            if(found == 1){ selected_rows_ids += '_'; }
                             selected_rows_ids += document.getElementById(\"".$this->unique_prefix."checkbox_\"+i).value;
                             found = 1;
@@ -3222,5 +3235,6 @@ class DataGrid
     //--------------------------------------------------------------------------
     function deleteRow($rid){
-        $this->rids = explode("-", $rid);
+        //$this->rids = explode("-", $rid); //FERNANDO
+    $this->rids = explode("_", $this->rid);
         $sql = "DELETE FROM $this->tbl_name WHERE $this->primary_key IN (-1 ";
         foreach ($this->rids as $key){
@@ -4017,5 +4031,7 @@ class DataGrid
                         break;
                     case "linktoview";
-                        $curr_url = $this->combineUrl("details", intval($row[(($this->getFieldOffset($this->primary_key) != -1) ? $this->getFieldOffset($this->primary_key) : 0)]));                         
+            //FERNANDO: Retiro intval porque si la clave no es un entero se jode el invento.
+                        //$curr_url = $this->combineUrl("details", intval($row[(($this->getFieldOffset($this->primary_key) != -1) ? $this->getFieldOffset($this->primary_key) : 0)]));
+                        $curr_url = $this->combineUrl("details", $row[(($this->getFieldOffset($this->primary_key) != -1) ? $this->getFieldOffset($this->primary_key) : 0)]);
                         $this->setUrlStringPaging($curr_url);
                         $this->setUrlStringSorting($curr_url);
@@ -4085,4 +4101,11 @@ class DataGrid
                             echo "<input class='class_checkbox' type='checkbox' name='".$this->getFieldRequiredType($field_name).$field_name."' id='".$this->getFieldRequiredType($field_name).$field_name."' title='".$this->getFieldTitle($field_name)."' value='".trim($field_value)."' ".$checked." ".$readonly." ".$on_js_event.">".$this->nbsp;
                             break;
+                        //FERNANDO incluyo tipo sha1...FALTA ACABAR
+                        case "passwdhash":
+                            $ret_hash =$this->nbsp."<input class='class_textbox' ".$field_width." type='text' title='".$this->getFieldTitle($field_name)."' name='".$this->getFieldRequiredType($field_name).$field_name."' value='".trim($field_value)."' $field_maxlength ".$on_js_event.">";
+                            //if(!$readonly) $ret_hash .= "<a class='".$this->unique_prefix."class_a2' title='".$this->getFieldTitle($field_name)."' href=\"#\" onclick=\"javascript:alert(".$this->unique_prefix."computaHash('hola'));\" ><img src='".$this->directory."images/".$this->css_class."/llave.png' border='0' alt='".$this->lang['set_hash_pswd']."' title='".$this->lang['set_hash_pswd']."' align='top' style='margin:3px;margin-left:6px;margin-right:6px;' /></a>".$this->nbsp;
+                            if(!$readonly) $ret_hash .= "<a class='".$this->unique_prefix."class_a2' title='".$this->getFieldTitle($field_name)."' href=\"javascript:;\" onclick='document.".$this->unique_prefix."frmEditRow.".$this->getFieldRequiredType($field_name).$field_name.".value=".$this->unique_prefix."computaHash(document.".$this->unique_prefix."frmEditRow.".$this->getFieldRequiredType($field_name).$field_name.".value);'><img src='".$this->directory."images/".$this->css_class."/llave.png' border='0' alt='".$this->lang['set_hash_pswd']."' title='".$this->lang['set_hash_pswd']."' align='top' style='margin:3px;margin-left:6px;margin-right:6px;' /></a>".$this->nbsp;
+                            return $ret_hash;
+                            break;
                         case "date":
                             $ret_date  = $this->nbsp."<input class='class_textbox' ".$field_width." readonly type='text' title='".$this->getFieldTitle($field_name)."' name='".$this->getFieldRequiredType($field_name).$field_name."' value='".trim($field_value)."' $field_maxlength ".$on_js_event.">";
@@ -4631,4 +4654,6 @@ class DataGrid
         if($type == ""){
             $mode_type = (isset($this->modes[$mode]['type'])) ? $this->modes[$mode]['type'] : "";
+            //FERNANDO. HACIENDO QUE EL MODO EDIT SIEMPRE SEAN LINKS
+            if (($this->layout_type == "edit")&&($this->mode=="edit")) $mode_type="link";
         }else{
             $mode_type = $type;
@@ -4717,4 +4742,10 @@ class DataGrid
             }
         }
+        // FERNANDO FUNCIONES DE HASH SHA1
+        if (!file_exists($this->directory.'scripts/hash.js')) {            
+            echo "<label class='class_error_message no_print'>Cannot find file: <b>".$this->directory."scripts/hash.js</b>. Check if this file exists and you use a correct path!</label><br /><br />";
+        }else{
+            echo "\n<script type='text/javascript' src='".$this->directory."scripts/hash.js'></script>";
+        }

         // set WYSIWYG
@@ -4748,4 +4779,19 @@ class DataGrid
         echo "\n//-->\n";
         echo "</script>";
+        
+        // FERNANDO 
+        echo "<script type='text/javascript'>\n";
+        echo "<!--\n";
+        echo "function ".$this->unique_prefix."computaHash(valorprevio) {"
+            .$this->unique_prefix."respuesta= prompt(\"".$this->lang['intro_text_tohash']."\",\"\");
+            if(".$this->unique_prefix."respuesta!=\"\") 
+                ".$this->unique_prefix."respuesta=hex_sha1(".$this->unique_prefix."respuesta); 
+            else  
+                ".$this->unique_prefix."respuesta=valorprevio;
+            return ".$this->unique_prefix."respuesta;
+        }";
+        echo "\n//-->\n";
+        echo "</script>";                
+
     }

@@ -5068,4 +5114,5 @@ class DataGrid
             $this->lang['like%'] = "like%";  // "begins with";
             $this->lang['%like'] = "%like";  // "ends with";
+            $this->lang['%like%'] = "%like%";  // "middle with";
             $this->lang['loading_data'] = "loading data...";
             $this->lang['max'] = "max";
@@ -5111,4 +5158,9 @@ class DataGrid
             $this->lang['wrong_parameter_error'] = "Wrong parameter in <b>_FIELD_</b>: _VALUE_";
             $this->lang['yes'] = "Yes";
+            $this->lang['export_to_excel_confirm'] = "Do you want to export datagrid content into export.cvs file?";
+            $this->lang['export_to_xml_confirm'] = "Do you want to export datagrid content into export.xml file?";
+            $this->lang['set_hash_pswd'] = "Set password to hash";
+            $this->lang['intro_text_tohash'] = "Enter text to hash:";
+            $this->lang['sort'] = "Sort this column";
         }
     }

Comentarios