phpBMS

root/trunk/phpbms/include/search_class.php

Revision 755, 45.2 KB (checked in by brieb, 2 years ago)
  • fixed 'where' dropdown losing performed search selected position.
  • Property svn:keywords set to LastChangedBy LastChangedDate LastChangedRevision
Line 
1<?php
2/*
3 $Rev$ | $LastChangedBy$
4 $LastChangedDate$
5 +-------------------------------------------------------------------------+
6 | Copyright (c) 2004 - 2010, Kreotek LLC                                  |
7 | All rights reserved.                                                    |
8 +-------------------------------------------------------------------------+
9 |                                                                         |
10 | Redistribution and use in source and binary forms, with or without      |
11 | modification, are permitted provided that the following conditions are  |
12 | met:                                                                    |
13 |                                                                         |
14 | - Redistributions of source code must retain the above copyright        |
15 |   notice, this list of conditions and the following disclaimer.         |
16 |                                                                         |
17 | - Redistributions in binary form must reproduce the above copyright     |
18 |   notice, this list of conditions and the following disclaimer in the   |
19 |   documentation and/or other materials provided with the distribution.  |
20 |                                                                         |
21 | - Neither the name of Kreotek LLC nor the names of its contributore may |
22 |   be used to endorse or promote products derived from this software     |
23 |   without specific prior written permission.                            |
24 |                                                                         |
25 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS     |
26 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT       |
27 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
28 | PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT      |
29 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,   |
30 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT        |
31 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,   |
32 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY   |
33 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT     |
34 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE   |
35 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.    |
36 |                                                                         |
37 +-------------------------------------------------------------------------+
38*/
39        class displayTable{
40                var $isselect;
41                var $thetabledef;
42                var $ref;
43                var $thecolumns;
44                var $querystatement;
45                var $numrows=0;
46                var $recordoffset=0;
47                var $queryresult;
48                var $querysortorder="";
49                var $base="";
50                var $sqlerror="";
51                var $showGroupings = true;
52
53                var $db;
54
55                function displayTable($db){
56                        $this->db=$db;
57                }
58
59
60                //given a table id, go grab the table definition information for that table
61                function getTableDef($id){
62
63                        $querystatement="
64                                SELECT
65                                        tabledefs.id,
66                                        tabledefs.uuid,
67                                        maintable,
68                                        querytable,
69                                        tabledefs.displayname,
70                                        addfile,
71                                        editfile,
72                                        importfile,
73                                        deletebutton,
74                                        type,
75                                        defaultwhereclause,
76                                        defaultsortorder,
77                                        defaultsearchtype,
78                                        defaultcriteriafindoptions,
79                                        defaultcriteriaselection,
80                                        modules.name,
81                                        searchroleid,
82                                        advsearchroleid,
83                                        viewsqlroleid,
84                                        editroleid,
85                                        addroleid
86                                FROM
87                                        tabledefs INNER JOIN modules on tabledefs.moduleid = modules.uuid
88                                WHERE
89                                        tabledefs.uuid= '".$id."'";
90
91                        $queryresult=$this->db->query($querystatement);
92
93                        if ($this->db->numRows($queryresult)<1) $error = new appError(1,"table definition not found: ".$id);
94
95                        $therecord=$this->db->fetchArray($queryresult);
96
97                        if(!hasRights($therecord["searchroleid"]))
98                                goURL(APP_PATH."noaccess.php");
99
100                        return $therecord;
101                }//end function getTableDef
102
103
104                /**
105                 * retrieves groupings for a tabledefs
106                 *
107                 * @param string $id tabledef uuid
108                 */
109                function getTableGroupings($id){
110
111                        $groupings = array();
112
113                        $querystatement = "
114                                SELECT
115                                        `field`,
116                                        `name` AS displayname,
117                                        `ascending`,
118                                        `roleid`
119                                FROM
120                                        tablegroupings
121                                WHERE
122                                        tabledefid = '".$id."'
123                                ORDER BY
124                                        displayorder";
125
126                        $queryresult = $this->db->query($querystatement);
127
128                        while($therecord = $this->db->fetchArray($queryresult)) {
129
130                                if(hasRights($therecord["roleid"],false))
131                                        $groupings[] = $therecord;
132
133                        }//endwhile
134
135                        return $groupings;
136
137                }//end function getTableGroupings
138
139
140                /**
141                 * Retrieves table definition's columns (to be displayed)
142                 *
143                 * @param string $id tabledefs uuid
144                 */
145                function getTableColumns($id){
146
147                        $thecolumns = array();
148
149                        $querystatement = "
150                                SELECT
151                                        name,
152                                        `column`,
153                                        align,
154                                        sortorder,
155                                        footerquery,
156                                        wrap,
157                                        size,
158                                        format,
159                                        roleid
160                                FROM
161                                        tablecolumns
162                                WHERE
163                                        tabledefid = '".$id."'
164                                ORDER BY
165                                        displayorder";
166
167                        $queryresult = $this->db->query($querystatement) ;
168
169                        while($therecord = $this->db->fetchArray($queryresult))
170                                if(hasRights($therecord["roleid"], false))
171                                        $thecolumns[] = $therecord;
172
173                        return $thecolumns;
174
175                }//end function getTableColumns
176
177
178                function showResultHeader(){
179                        ?>
180                        <tr>
181                        <?php
182                        $columncount=count($this->thecolumns);
183                        $i=1;
184
185                        foreach ($this->thecolumns as $therow){ ?>
186                <th nowrap="nowrap" align="<?php echo $therow["align"]?>" <?php if($therow["size"]) echo "width=\"".$therow["size"]."\" ";?> >
187                        <input name="sortit<?php echo $i?>" type="hidden" value="<?php echo $therow["name"]?>" />
188                        <a href="/" onclick="doSort(<?php echo $i?>);return false;"><?php echo $therow["name"]?></a>
189                        <?php
190                                // If sorting on this column give the option to reverse the sort order.
191                                if ($this->querysortorder==$therow["column"] || $this->querysortorder==$therow["sortorder"])
192                        {?>&nbsp;<a href="/" onclick="doDescSort();return false;"><img src="<?php echo APP_PATH?>common/image/down_arrow.gif" alt="dn" title="dn" width="10" height="10" border="0" /></a><input name="desc" type="hidden" value="" />
193                <?php } elseif ($this->querysortorder==$therow["column"]." DESC" || $this->querysortorder==$therow["sortorder"]." DESC")
194                {?> &nbsp;<a href="/" onclick="doSort(<?php echo $i?>);return false;"><img src="<?php echo APP_PATH?>common/image/up_arrow.gif" alt="up" title="up" width="10" height="10" border="0" /></a>
195                <?php } ?></th><?php
196                                $i++;
197                        }//end foreach
198                        ?></tr><?php
199
200                }//end function
201
202                //output a query
203                function showResultRecords() {
204                        if(!isset($this->options["new"])) $this->options["new"]=1;
205                        if(!isset($this->options["select"])) $this->options["select"]=1;
206                        if(!isset($this->options["edit"])) $this->options["edit"]=1;
207
208                        $rownum=1;
209                        $this->db->seek($this->queryresult,0);
210
211                        //groupings
212                        if($this->showGroupings){
213                                for($i = 0; $i < count($this->thegroupings); $i++){
214                                        $this->thegroupings[$i]["theValue"]="";
215                                }
216
217                        }
218
219                        while($therecord = $this->db->fetchArray($this->queryresult)){
220
221                                // more groupings
222                                if($this->showGroupings){
223                                        for($i = 0; $i < count($this->thegroupings); $i++){
224                                                if($this->thegroupings[$i]["theValue"] != $therecord["_group".($i+1)]){
225                                                        $this->thegroupings[$i]["theValue"] = $therecord["_group".($i+1)];
226                                                        ?><tr class="queryGroup"><td colspan = "<?php echo count($this->thecolumns)?>" <?php if($i) echo 'style = "padding-left:'.($i*15).'px"'?>>
227                                                        <?php
228                                                                if($this->thegroupings[$i]["displayname"])
229                                                                        echo htmlQuotes($this->thegroupings[$i]["displayname"].": ");
230                                                                echo $therecord["_group".($i+1)];
231                                                         ?>
232                                                        </td></tr><?php
233
234                                                        $rownum = 1;
235
236                                                }//endif
237                                        }//endfor
238                                }//endif
239
240                                ?><tr class="qr<?php echo $rownum?>" id="r-<?php echo $therecord["theid"]?>" <?php
241
242                                if ($this->options["select"]) {
243                                        ?> onclick="clickIt(this,event,'<?php echo $this->isselect?>')" <?php
244                                }
245                                if ($this->options["edit"]) {
246                                        ?> ondblclick="editThis(this);"<?php
247                                }
248                                ?> ><?php
249
250                                if ($rownum==1) $rownum++; else $rownum=1;
251
252                                foreach($this->thecolumns as $thecolumn){
253                                        ?><td align="<?php echo $thecolumn["align"]?>" <?php if(!$thecolumn["wrap"]) echo "nowrap=\"nowrap\""?>><?php echo (($therecord[$thecolumn["name"]]!=="")?formatVariable($therecord[$thecolumn["name"]],$thecolumn["format"]):"&nbsp;")?></td><?php
254                                }
255                                ?></tr><?php
256                        }//endwhile
257
258
259                }//end function
260
261
262                // display a no results page
263                function showNoResults(){
264                        $i=count($this->thecolumns);?>
265                        <tr class="norecords"><td colspan="<?php echo $i?>">
266                                <?php if(!$this->sqlerror) {?>
267                                        No Results Found
268                                <?php } else {?>
269                                        Invalid Search
270                                <?php } ?>
271                        </td></tr>
272                        <?php
273                }
274
275                function initialize($id){
276
277                        $this->thetabledef = $this->getTableDef($id);
278
279                        $this->ref = $this->thetabledef["id"];
280                        $this->uuid = $this->thetabledef["uuid"];
281
282                        //next we set the columns
283                        $this->thecolumns=$this->getTableColumns($this->uuid);
284                        $this->thegroupings = $this->getTableGroupings($this->uuid);
285
286                }//end function initialize
287
288
289                function issueQuery(){
290
291                        //save the query for total and display purposes
292                        $_SESSION["thequerystatement"] = $this->querystatement;
293                        //Add limit (settings)
294                        $_SESSION["thequerystatement"].=" limit ".$this->recordoffset.", ".RECORD_LIMIT.";";
295
296                        $this->db->logError=false;
297                        $this->db->stopOnError=false;
298
299                        $this->queryresult = $this->db->query($_SESSION["thequerystatement"]);
300
301                        $this->db->logError=true;
302                        $this->db->stopOnError=true;
303
304                        if($this->queryresult){
305                                 $this->numrows=$this->db->numRows($this->queryresult);
306                                 if($this->numrows==RECORD_LIMIT or $this->recordoffset!=0){
307                                    //if you max the record limit or are already offsetiing get the true count
308
309                                        $truecountstatement = "
310                                                SELECT
311                                                        count(distinct ".$this->thetabledef["maintable"].".id) as thecount
312                                                        ".getSearchFrom($this->querystatement);
313                                        $truequeryresult=$this->db->query($truecountstatement);
314
315                                        $truerecord=$this->db->fetchArray($truequeryresult);
316                                        $this->truecount=$truerecord["thecount"];
317                                 }
318                                 else $this->truecount=$this->numrows;
319                                $this->sqlerror="";
320                        }else{
321                                $this->sqlerror=$this->db->error;
322                                $this->numrows=0;
323                                $this->truecount=0;
324                        }
325                        $_SESSION["sqlerror"]=$this->sqlerror;
326                }
327
328                function getIDs($variables){
329                        $theids=array();
330                        foreach($variables as $key=>$value){
331                                if (substr($key,0,5)=="check") $theids[]=$value;
332                        }
333                        return $theids;
334                }
335
336                //===============
337                //Query Functions
338                //===============
339                // replace variables
340                // strings with entrys like " {{$ENTRY}} "
341                // get everything in the {{ }} evaluated
342                function subout($string){
343
344                        while(strpos($string,"{{")){
345                                $start=strpos($string,"{{");
346                                $startsubout=$start+2;
347                                $endsubout=strpos($string,"}}");
348                                $end=$endsubout+2;
349                                $temp="";
350                                eval(stripslashes("\$temp=".substr($string,$startsubout,$endsubout-$startsubout).";"));
351                                $string=substr($string,0,$start).$temp.substr($string,$end);
352                        }
353
354                        return $string;
355
356                }//end function
357
358        }//end class
359
360
361
362
363
364        //=====================================================================================================================
365        class displaySelectTable extends displayTable{
366                var $isselect=true;
367                var $querytype="select";
368                var $valuefield;
369                var $displayfield;
370                var $whereclause;
371                var $searchvalue;
372                var $fieldname;
373
374                function displaySelectTable($db){
375                        $this->db = $db;
376                }
377
378                function initialize($variables){
379                        parent::initialize($variables["tableid"]);
380
381                        $this->valuefield=stripslashes($variables["valuefield"]);
382                        $this->displayfield=stripslashes($variables["displayfield"]);
383                        $this->whereclause=stripslashes($variables["whereclause"]);
384                        $this->searchvalue=stripslashes($variables["value"]);
385                        $this->fieldname=stripslashes($variables["name"]);
386
387                        if(isset($_SESSION["tableparams"][$this->ref]))
388                                $this->querysortorder=$_SESSION["tableparams"][$this->ref]["querysortorder"];
389                        else
390                                $this->querysortorder=$this->thetabledef["defaultsortorder"];
391                }
392
393
394                function issueInitialQuery(){
395
396                        $querystatement="SELECT ".$this->valuefield." AS value, ".$this->displayfield." AS display FROM ".$this->thetabledef["maintable"]." WHERE ";
397                        $querystatement.="(".$this->displayfield." LIKE \"".$this->searchvalue."%\") ";
398
399                        if($this->whereclause)
400                                $querystatement.="AND (".$this->whereclause.")";
401
402                        $queryresult=$this->db->query($querystatement);
403
404                        return $queryresult;
405                }
406
407
408                function issueQuery(){
409                        $querycolumns = "";
410                        $tempSortOrder = "";
411
412                        //GROUPING SETUP
413                        if($this->showGroupings){
414                                $i =1 ;
415                                foreach ($this->thegroupings as $thegroup){
416                                        $querycolumns .= ", ".$thegroup["field"]." as \"_group".$i."\" ";
417                                        $tempSortOrder .= ", ".$thegroup["field"];
418                                        if($thegroup["ascending"] == 0)
419                                                $tempSortOrder.=" DESC";
420                                        $i++;
421                                }
422                                if($i > 1){
423                                        $tempSortOrder = substr($tempSortOrder,2).", ";
424                                }
425                        }
426
427                        foreach ($this->thecolumns as $therow)
428                                $querycolumns.=", ".$therow["column"]." as \"".$therow["name"]."\"";
429                        $querycolumns=substr($querycolumns,2);
430
431                        $this->querystatement = "SELECT DISTINCT ".$this->valuefield." AS value, ".$this->displayfield." AS display, ".$querycolumns." FROM ".$this->thetabledef["querytable"]." WHERE";
432                        $this->querystatement.="(".$this->displayfield." LIKE \"".$this->searchvalue."%\") ";
433                        if($this->whereclause)
434                                $this->querystatement.="AND (".$this->whereclause.")";
435
436                        $tempSortOrder.= $this->querysortorder;
437                        $this->querystatement.=" ORDER BY ".$tempSortOrder;
438
439                        $_SESSION["tableparams"][$this->ref]["querysortorder"]=$this->querysortorder;
440
441                        parent::issueQuery();
442
443                }//end function
444        }//end class
445
446
447
448        //=====================================================================================================================
449        class displaySearchTable extends displayTable{
450                var $isselect=false;
451                var $therecords="";
452
453                var $querytype="search";
454
455                var $queryjoinclause="";
456                var $querywhereclause="";
457
458                var $savedfindoptions="";
459                var $savedselection="";
460                var $savedstartswithfield="";
461                var $savedstartswith="";
462                var $savedendswith="";
463
464                var $tableoptions;
465
466                /**
467                 * get's table options (like new, edit, print)
468                 *
469                 * @param string $id tabledefs uuid;
470                 */
471                function getTableOptions($id){
472
473                        $options = Array();
474
475                        $querystatement = "
476                                SELECT
477                                        id,
478                                        name,
479                                        `option`,
480                                        needselect,
481                                        othercommand,
482                                        roleid,
483                                        displayorder
484                                FROM
485                                        tableoptions
486                                WHERE
487                                        tabledefid = '".$id."'
488                                ORDER BY
489                                        othercommand,
490                                        displayorder,
491                                        id";
492
493                        $queryresult = $this->db->query($querystatement);
494
495                        while($therecord=$this->db->fetchArray($queryresult)) {
496
497                                if($therecord["othercommand"]) {
498
499                                        $options["othercommands"][] = array(
500                                                "id" => $therecord["id"],
501                                                "name" => $therecord["option"],
502                                                "roleid" => $therecord["roleid"],
503                                                "displayorder" => $therecord["displayorder"],
504                                                "needselect" => $therecord["needselect"]
505                                        );
506
507                                }else{
508
509                                        $options[$therecord["name"]]["allowed"]=$therecord["option"];
510                                        $options[$therecord["name"]]["roleid"]=$therecord["roleid"];
511                                        $options[$therecord["name"]]["needselect"]=$therecord["needselect"];
512
513                                }//endif
514
515                        }//endwhile
516//debug($options);
517                        return $options;
518
519                }//end getTableOptions
520
521
522                /**
523                 * Builds table definitions findoptions (find select box)
524                 *
525                 * @param string $id tabledefs UUID
526                 */
527                function getTableQuickSearchOptions($id){
528
529                        $findoptions = Array();
530                        $querystatement = "
531                                SELECT
532                                        name,
533                                        search,
534                                        roleid
535                                FROM
536                                        tablefindoptions
537                                WHERE
538                                        tabledefid = '".$id."'
539                                ORDER BY
540                                        displayorder";
541
542                        $queryresult = $this->db->query($querystatement);
543
544                        while($therecord = $this->db->fetchArray($queryresult)){
545
546                                $therecord["search"] = $this->subout($therecord["search"]);
547                                $findoptions[] = $therecord;
548
549                        }//endif
550
551                        return $findoptions;
552
553                }//end function getTableQuickSearchOptions
554
555                /**
556                 * Builds table searchable fields list
557                 *
558                 * @param string $id tabledefs uuid
559                 */
560                function getTableSearchableFields($id){
561
562                        $searchablefields = Array();
563
564                        $querystatement = "
565                                SELECT
566                                        id,
567                                        field,
568                                        name,
569                                        type
570                                FROM
571                                        tablesearchablefields
572                                WHERE
573                                        tabledefid = '".$id."'
574                                ORDER BY
575                                        displayorder";
576
577                        $queryresult = $this->db->query($querystatement);
578
579                        while($therecord = $this->db->fetchArray($queryresult))
580                                $searchablefields[] = $therecord;
581
582                        return $searchablefields;
583
584                }//end function getTableSearchableFields
585
586
587
588                function displaySearch(){
589
590                ?>
591<form name="search" id="search" method="post" action="<?php echo htmlentities($_SERVER["PHP_SELF"])?>?id=<?php echo $this->thetabledef["uuid"]?>" onsubmit="setSelIDs(this);return true;">
592<input id="tabledefid" name="tabledefid" type="hidden" value="<?php echo $this->thetabledef["id"]?>" />
593<input id="theids" name="theids" type="hidden" value="" />
594<input id="advancedsearch" name="advancedsearch" type="hidden" value="" />
595<input id="advancedsort" name="advancedsort" type="hidden" value="" />
596<?php if ($this->querytype!="" and $this->querytype!="search") {
597                $temptype=$this->querytype;
598                if($temptype=="advanced search")
599                        $temptype="advanced or saved search";
600                echo "<p><i>(currently showing ".$temptype.")</i></p>";
601        }
602?>
603<ul class="tabs">
604        <li id="basicSearchT" class="tabsSel"><a href="/" onclick="switchSearchTabs(this);return false">basic</a></li>
605        <?php if(hasRights($this->thetabledef["advsearchroleid"])){?><li id="advancedSearchT"><a href="/" onclick="switchSearchTabs(this,'<?php echo APP_PATH?>');return false">advanced</a></li><?php } //end access ?>
606        <li id="loadSearchT"><a href="/" onclick="switchSearchTabs(this,'<?php echo APP_PATH?>');return false">load search</a></li>
607        <li id="saveSearchT"><a href="/" onclick="switchSearchTabs(this,'<?php echo APP_PATH?>');return false">save search</a></li>
608        <li id="advancedSortT"><a href="/" onclick="switchSearchTabs(this,'<?php echo APP_PATH?>');return false">sorting</a></li>
609</ul>
610<div class="box" id="searchBox">
611        <div id="basicSearchTab">
612
613            <p id="bstFindP" class="big">
614
615                <label for="find">find</label><br />
616                <select name="find" id="find" tabindex="1">
617                <?php
618
619                        foreach($this->findoptions as $option) {
620
621                            if(hasRights($option["roleid"])){
622
623                                ?><option value="<?php echo formatVariable($option["name"]) ?>" <?php
624
625                                    if($this->querytype=="search" && $option["name"] == $this->savedfindoptions)
626                                        echo 'selected="selected"';
627
628                                    ?>><?php echo formatVariable($option["name"])?></option><?php
629
630                            }//endif
631
632                        }//enforeach
633
634                ?>
635                </select>
636
637            </p>
638
639            <p id="bstStartsWithFieldP" class="big">
640                <label for="startswithfield">where</label><br />
641                <select name="startswithfield" id="startswithfield" tabindex="1">
642                <?php
643
644                    $i=0;
645
646                    foreach($this->searchablefields as $searchField) {
647
648                            ?><option value="<?php echo $searchField["id"]?>" <?php
649
650                                if(!isset($this->savedstartswithfield)) {
651                                    if($this->querytype != "search" && $i == 0)
652                                        echo 'selected="selected"';
653                                } else {
654                                    if($this->querytype == "search" && addslashes($searchField["id"]) == $this->savedstartswithfield)
655                                        echo 'selected="selected"';
656                                }//endif
657
658                            echo ">".$searchField["name"]."</option>\n";
659
660                        $i++;
661
662                    }//endforeach
663                    ?>
664                </select>
665
666            </p>
667
668            <p id="bstSearchButtonP" class="big">
669                <input name="command" id="searchbutton" type="submit" class="Buttons" value="search" tabindex="2"/>
670            </p>
671
672            <p id="bstStartsWithP" class="big">
673
674                <label for="startswith">starts with</label><br />
675                <input id="startswith" name="startswith" type="text"  value="<?php if($this->querytype=="search" and isset($this->savedstartswith)) echo formatVariable(stripslashes(stripslashes($this->savedstartswith))) ?>" size="35" maxlength="128" tabindex="1"/>
676
677            </p>
678
679
680            <p id="bstSelectionP">
681                <select name="Selection" tabindex="2">
682                    <option value="new" <?php if ($this->querytype!="search" or ($this->querytype=="search" and $this->savedselection=="new") ) echo "selected=\"selected\""?> >new result</option>
683                    <option value="add" <?php if ($this->querytype=="search" and $this->savedselection=="add")echo "selected=\"selected\""?>>add to result</option>
684                    <option value="remove" <?php if ($this->querytype=="search" and $this->savedselection=="remove")echo "selected=\"selected\""?>>remove from result</option>
685                    <option value="narrow" <?php if ($this->querytype=="search" and $this->savedselection=="narrow")echo "selected=\"selected\""?>>narrow result</option>
686                </select>
687            </p>
688
689            <p id="bstResetButtonP">
690                <input name="command" type="submit" id="reset" class="smallButtons" value="reset" accesskey="t" title="(access key+t)" tabindex="2"/>
691            </p>
692
693</div><?php if(hasRights($this->thetabledef["advsearchroleid"])){?><div id="advancedSearchTab" style="display:none;"></div><?php } //end access ?>
694<div id="loadSearchTab" style="display:none;padding:0px;margin:0px;"></div>
695<div id="saveSearchTab" style="display:none;margin:0px;padding:0px;margin:0px;">
696        <div id="saveSearchReults" style="display:none"></div>
697        <table cellpadding="0" cellspacing="0" border="0">
698                <tr>
699                        <td width="100%">
700                                <p><label for="saveSearchName">save current search as</label>
701                                        <br />
702                                        <input id="saveSearchName" name="saveSearchName" type="text"  value="" size="35" maxlength="128" onkeyup="enableSave(this)" />
703                                </p>
704                        </td>
705                        <td align="right">
706                                <p>
707                                        <br />
708                                        <input id="saveSearch" onclick="saveMySearch('<?php echo APP_PATH ?>')" disabled="disabled" type="button" class="Buttons" value="save search" />
709                                </p>
710                        </td>
711                </tr>
712        </table></div><div id="advancedSortTab" style="display:none;padding:0px;margin:0px;"></div></div><?php
713        }//end function
714
715
716                function displayQueryButtons() {
717
718                        global $phpbms;
719
720                        ?><div id="resultInfoDiv"><?php
721
722                        if(!isset($this->tableoptions["new"])){
723                                 $this->tableoptions["new"]["allowed"]=0;
724                                 $this->tableoptions["new"]["roleid"]=0;
725                                 $this->tableoptions["new"]["needselect"]=0;
726                        }
727                        if(!isset($this->tableoptions["select"])) {
728                                $this->tableoptions["select"]["allowed"]=0;
729                                $this->tableoptions["select"]["roleid"]=0;
730                                $this->tableoptions["select"]["needselect"]=0;
731                        }
732                        if(!isset($this->tableoptions["edit"])){
733                                 $this->tableoptions["edit"]["allowed"]=0;
734                                 $this->tableoptions["edit"]["roleid"]=0;
735                                 $this->tableoptions["edit"]["needselect"]=0;
736                        }
737                        if(!isset($this->tableoptions["printex"])) {
738                                $this->tableoptions["printex"]["allowed"]=0;
739                                $this->tableoptions["printex"]["roleid"]=0;
740                                $this->tableoptions["printex"]["needselect"]=0;
741                        }
742                        if(!isset($this->tableoptions["import"])) {
743                                $this->tableoptions["import"]["allowed"]=0;
744                                $this->tableoptions["import"]["roleid"]=0;
745                                $this->tableoptions["import"]["needselect"]=0;
746                        }
747                        if(!isset($this->tableoptions["othercommands"])) $this->tableoptions["othercommands"]=false;
748
749                        // If they have rights to see the SQL statement, spit it out here.
750                        if(hasRights($this->thetabledef["viewsqlroleid"])) {
751
752                        ?><div id="sqlstatement">
753                                <fieldset>
754                                        <legend>SQL Statement</legend>
755                                        <div id="theSqlText" class="mono small"><?php echo stripslashes(htmlQuotes($this->querystatement))?></div>
756                                </fieldset><?php
757
758                                if($this->sqlerror) {?>
759                                <fieldset>
760                                        <legend><span style="text-transform:capitalize">SQL</span> Error</legend>
761                                        <div><?php echo $this->sqlerror?></div>
762                                </fieldset><?php
763
764                                }?>
765                        </div>
766
767                        <?php }
768
769                        ?><div id="commandSet"><?php
770
771                        if($this->numrows){
772                                ?>
773                                <div id="numCount" align="right" class="small"><input type="hidden" id="deleteCommand" name="deleteCommand" value="" /><?php
774
775                                if ($this->truecount<=RECORD_LIMIT)
776                                        echo "<div>records:&nbsp;".$this->numrows."</div>";
777                                else {
778
779                                ?>
780                                        <input name="offset" type="hidden" value="" /><select name="offsetselector" onchange="this.form.offset.value=this.value;this.form.submit();">
781                                                <?php
782
783                                                        $displayedoffset=0;
784                                                        while($displayedoffset<$this->truecount){
785                                                                ?><option value="<?php echo $displayedoffset?>" <?php if($displayedoffset==$this->recordoffset) echo "selected=\"selected\"";?>><?php echo ($displayedoffset+1)?>-<?php if($displayedoffset+RECORD_LIMIT<$this->truecount) echo ($displayedoffset+RECORD_LIMIT); else echo $this->truecount;?></option><?php
786                                                                $displayedoffset+=RECORD_LIMIT;
787                                                        }
788
789                                                ?>
790                                          </select> of <?php echo $this->truecount;
791                                        if($this->recordoffset>0){
792                                                ?><button type="button" class="graphicButtons buttonRew" onclick="document.search.offset.value=<?php echo $this->recordoffset-RECORD_LIMIT ?>;document.search.submit();"><span>prev.</span></button><?php
793                                        }
794                                        if(($this->numrows+$this->recordoffset)<$this->truecount){
795                                                ?><button type="button" class="graphicButtons buttonFF" onclick="document.search.offset.value=<?php echo $this->recordoffset+RECORD_LIMIT ?>;document.search.submit();"><span>next</span></button><?php
796                                        }
797
798                                }//end if ?></div><?php
799                        }//end if?>
800
801                                <ul id="recordCommands">
802                                <?php
803                                        $showFirst = ' id="firstToolbarItem" ';
804
805                                        if ($this->tableoptions["new"]["allowed"] && hasRights($this->tableoptions["new"]["roleid"])) {
806
807                                        ?><li <?php echo $showFirst?>>
808                                                <a href="#" id="newRecord" class="newRecord" accesskey="n" title="new record (alt + n)" onclick="addRecord();return false;"><span>new</span></a>
809                                          </li><?php
810                                        $showFirst = NULL;
811                                }
812
813                                if($this->numrows) {
814                                        if ($this->tableoptions["edit"]["allowed"] && hasRights($this->tableoptions["edit"]["roleid"])) {
815                                                ?><li <?php echo $showFirst?>>
816                                                        <a href="#" id="editRecord" class="editRecordDisabled" accesskey="e" onclick="return editButton();" title="edit record (alt + e)"><span>edit</span></a>
817                                                </li>
818                                                <?php
819                                                $showFirst = NULL;
820                                        }//end if
821
822                                        if($this->thetabledef["deletebutton"] == "delete") {
823                                                ?><li <?php echo $showFirst?>>
824                                                        <a href="#" id="deleteRecord" class="deleteRecordDisabled" accesskey="d" onclick="confirmDelete('delete');return false" title="delete record (alt + d)"><span>delete</span></a>
825                                                </li>
826                                                <?php
827                                                $showFirst = NULL;
828                                        }//end if
829
830                                        if($this->tableoptions["printex"]["allowed"] && hasRights($this->tableoptions["printex"]["roleid"])){
831                                                ?><li <?php echo $showFirst?>>
832                                                        <a href="#" id="print" class="print" accesskey="p" onclick="doPrint();return false" title="print report (alt + p)"><span>print</span></a>
833                                                        <input type="hidden" id="doprint" name="doprint" value="no" />
834                                                </li>
835                                                <?php
836                                                $showFirst = NULL;
837                                        }//end if
838                                }//end if --numrows--
839                                        if($this->tableoptions["othercommands"] || ($this->tableoptions["import"]["allowed"] && hasRights($this->tableoptions["import"]["roleid"])) || ($this->thetabledef["deletebutton"] != "delete" && $this->thetabledef["deletebutton"] != "NA") ){
840
841                                                ?><li <?php echo $showFirst?>>
842                                                        <a href="#" id="otherCommandButton" class="otherCommands" onclick="showDropDown('otherDropDown');return false" title="other commands"><span>other commands</span></a>
843                                                        <div id="otherDropDown" class="toolbarDropDowns" style="display:none">
844                                                                <ul>
845                                                                        <?php
846                                                                        if($this->thetabledef["deletebutton"] != "delete" && $this->thetabledef["deletebutton"] != "NA") {
847
848                                                                                ?>
849                                                                                <li><a class="needselectDisabled" href="#" title="(alt + d)" onclick="chooseOtherCommand('-1','<?php echo $this->thetabledef["deletebutton"]?>',this); return false;"><strong><?php echo $this->thetabledef["deletebutton"]?></strong></a></li>
850                                                                                <?php
851
852                                                                                $displayOrder = -1;
853
854                                                                        }else
855                                                                                $displayOrder = 0;
856
857                                                                        if($this->tableoptions["import"]["allowed"] && hasRights($this->tableoptions["import"]["roleid"])){
858
859                                                                                $class = '';
860                                                                                if($this->tableoptions["import"]["needselect"])
861                                                                                        $class = 'class="needselectDisabled"';
862                                                                                ?>
863                                                                                <li><a <?php echo $class; ?> href="#" title="" onclick="chooseOtherCommand('-2','', this); return false;">import</a></li>
864                                                                                <?php
865
866                                                                                $displayOrder = -1;
867
868                                                                        }else
869                                                                                $displayOrder = ($displayOrder != -1)? 0 : (-1);
870
871                                                                        if($this->tableoptions["othercommands"]){
872
873                                                                                foreach($this->tableoptions["othercommands"] as $command){
874
875                                                                                        if(hasRights($command["roleid"])){
876
877                                                                                                $aclass="";
878                                                                                                $liclass="";
879                                                                                                if($command["displayorder"] != $displayOrder){
880
881                                                                                                        $liclass = ' class="menuSep"';
882                                                                                                        $displayOrder = $command["displayorder"];
883
884                                                                                                }
885                                                                                                if($command["needselect"])
886                                                                                                                $aclass = ' class="needselectDisabled"';
887
888                                                                                                ?>
889                                                                                                <li<?php echo $liclass?>><a<?php echo $aclass ?> href="#" onclick="chooseOtherCommand('<?php echo $command["id"] ?>','',this); return false;"><?php echo $command["name"]?></a></li>
890                                                                                                <?php
891
892                                                                                        }//end if
893
894                                                                                }//endforeach
895
896                                                                        }//end if
897                                                                        ?>
898                                                                </ul>
899                                                        </div><input id="othercommands" name="othercommands" type="hidden"/>
900                                                </li>
901                                                <?php
902                                                $showFirst = NULL;
903                                        }//end if
904
905                                if($this->numrows){
906                                        if($this->tableoptions["select"]["allowed"] && hasRights($this->tableoptions["select"]["roleid"])){
907                                                ?><li <?php echo $showFirst?>>
908                                                        <a href="#" id="searchSelection" class="searchSelection" onclick="showDropDown('searchSelectionDropDown');return false" title="selection"><span>selection</span></a>
909                                                        <div id="searchSelectionDropDown" class="toolbarDropDowns" style="display:none">
910                                                        <ul>
911                                                                <li><a href="#" onclick="performToSelection('selectall');return false;" accesskey="a" title="select all (alt + a)">select all</a></li>
912                                                                <li><a href="#" onclick="performToSelection('selectnone');return false;" accesskey="x" title="select none (alt + x)">select none</a></li>
913                                                                <li class="menuSep"><a href="#" onclick="performToSelection('keepselected');return false;" accesskey="k" title="keep selected (alt + k)">show only selected records</a></li>
914                                                                <li><a href="#" onclick="performToSelection('omitselected');return false;" accesskey="o" title="omit selected (alt + o)">remove selected records from view</a></li>
915                                                        </ul>
916                                                        </div>
917                                                </li>
918                                                <?php
919                                                $showFirst = NULL;
920                                        }//end if
921
922                                }//end if numrows
923                                        if(hasRights($this->thetabledef["viewsqlroleid"])){
924                                                ?>
925                                                <li>
926                                                        <a href="#" id="showSQLButton" class="sqlUp" onclick="return false;" title="Show SQL Statement"><span>show SQL</span></a>
927                                                </li>
928                                                <?php }//end rights
929
930                                ?>
931                                </ul>
932                                </div></div>
933                        <?php
934                        $phpbms->bottomJS[] = ' var addFile = "'.APP_PATH.$this->thetabledef["addfile"].'"';
935                        $phpbms->bottomJS[] = ' var editFile = "'.APP_PATH.$this->thetabledef["editfile"].'"';
936
937                        //for the import page, "" == the general page instead.
938                        $import = ($this->thetabledef["importfile"])?$this->thetabledef["importfile"]:"modules/base/general_import.php?id=".urlencode($this->thetabledef["uuid"]);
939                        $phpbms->bottomJS[] = ' var importFile = "'.APP_PATH.$import.'"';
940
941                }//end method
942
943
944
945                function displayResultTable(){
946                        ?><script language="JavaScript" type="text/javascript">selIDs=new Array();</script><input name="newsort" type="hidden" value="" />
947                        <div id="queryTableContainer"><table class="querytable" border="0" cellpadding="0" cellspacing="0">
948                                <thead>
949                                        <?php $this->showResultHeader()?>
950                                </thead>
951                                <tfoot>
952                                        <?php $this->showResultFooter()?>
953                                </tfoot>
954                                <tbody id="resultTbody">
955                                        <?php
956                                                if($this->numrows>0)
957                                                        $this->showResultRecords();
958                                                else
959                                                        $this->showNoResults();
960                                        ?>
961                                </tbody>
962                        </table></div><?php
963
964                }//end method
965
966
967
968                function showResultFooter(){
969                        ?><tr class="queryfooter"><?php
970                        foreach ($this->thecolumns as $therow){
971                                ?><td align="<?php echo $therow["align"]?>"><?php
972                                if($therow["footerquery"]){
973                                        $querystatement="SELECT ".$therow["footerquery"]." as thet FROM ".$this->therecords;
974                                        $queryresult=$this->db->query($querystatement);
975
976                                        $therecord=$this->db->fetchArray($queryresult);
977                                        echo formatVariable($therecord["thet"],$therow["format"]);
978                                } else {echo "&nbsp;";}?></td><?php
979                        }//end foreach
980                        //keep this in here to close the total table
981                        ?></tr><?php
982                }//end function
983
984
985                /**
986                 * displays the relationships drop down
987                 */
988                function showRelationships(){
989
990                        $querystatement = "
991                                SELECT
992                                        id,
993                                        name
994                                 FROM
995                                        relationships
996                                 WHERE
997                                        fromtableid = '".$this->thetabledef["uuid"]."'
998                                ORDER BY
999                                        name";
1000
1001                        $queryresult = $this->db->query($querystatement);
1002
1003                        if (!$queryresult)
1004                                $error = new appError(1,"Error Retrieving Relationships");
1005
1006                        if ($this->db->numRows($queryresult)) {
1007
1008                                ?>
1009                                <div class="small">
1010                                show related records in <select id="relationship" name="relationship" onchange="setSelIDs(this.form);this.form.submit();"       disabled="disabled">
1011                                        <option value="" selected="selected" class="choiceListBlank">area...</option><?php
1012                                        while($therecord = $this->db->fetchArray($queryresult)){
1013
1014                                                ?><option value="<?php echo $therecord["id"]?>"><?php echo formatVariable($therecord["name"]) ?></option><?php
1015
1016                                        }//endif
1017                                ?></select></div>
1018                                <?php
1019
1020                        }//endif
1021                        ?></form><?php
1022
1023                }//end function showRelationships
1024
1025                function initialize($id){
1026
1027                        parent::initialize($id);
1028
1029                        $this->tableoptions=$this->getTableOptions($this->uuid);
1030
1031                        // now we need to populate the find (quick search) options
1032                        $this->findoptions=$this->getTableQuickSearchOptions($this->uuid);
1033
1034                        // next we need to get a list of  searchable fields for the quick search drop down
1035                        $this->searchablefields=$this->getTableSearchableFields($this->uuid);
1036
1037
1038                        //check to see if criteria has been saved to Session
1039                        if(isset($_SESSION["tableparams"][$this->ref]))
1040                                //grab the session
1041                                $this->loadQueryParameters($_SESSION["tableparams"][$this->ref]);
1042                        else{
1043                                $this->loadQueryDefaults();
1044                        }
1045
1046                }
1047
1048                function issueQuery(){
1049                        $querycolumns="";
1050                        $tempSortOrder = "";
1051
1052                        //GROUPING SETUP
1053                        if($this->showGroupings){
1054                                $i =1 ;
1055                                foreach ($this->thegroupings as $thegroup){
1056                                        $querycolumns .= ", ".$thegroup["field"]." as \"_group".$i."\" ";
1057                                        $tempSortOrder .= ", ".$thegroup["field"];
1058                                        if($thegroup["ascending"] == 0)
1059                                                $tempSortOrder.=" DESC";
1060                                        $i++;
1061                                }
1062                                if($i > 1){
1063                                        $tempSortOrder = substr($tempSortOrder,2).", ";
1064                                }
1065                        }
1066
1067
1068                        foreach ($this->thecolumns as $therow)
1069                                $querycolumns.=", ".$therow["column"]." as \"".$therow["name"]."\"";
1070                        $querycolumns=substr($querycolumns,2);
1071
1072                        $tempSortOrder .= $this->querysortorder;
1073                        $this->therecords=$this->thetabledef["querytable"]." ".$this->queryjoinclause." WHERE ".$this->querywhereclause." ORDER BY ".$tempSortOrder;
1074                        $this->querystatement = "SELECT DISTINCT ".$this->thetabledef["maintable"].".id as theid,".$querycolumns." FROM ".$this->therecords;
1075
1076                        parent::issueQuery();
1077                }//end function
1078
1079                function loadQueryParameters($params){
1080
1081                        $this->querytype=$params["querytype"];
1082                        $this->queryjoinclause=$params["queryjoinclause"];
1083                        $this->querysortorder=$params["querysortorder"];
1084                        $this->querywhereclause=$params["querywhereclause"];
1085
1086                        $this->showGroupings =  $params["showGroupings"];
1087
1088                        $this->savedfindoptions=$params["savedfindoptions"];
1089                        $this->savedselection=$params["savedselection"];
1090                        $this->savedstartswithfield=$params["savedstartswithfield"];
1091                        $this->savedstartswith=$params["savedstartswith"];
1092                        $this->savedendswith=$params["savedendswith"];
1093                        $this->recordoffset=$params["recordoffset"];
1094                        $this->sqlerror=$params["sqlerror"];
1095
1096                }
1097
1098                function saveQueryParameters(){
1099
1100                        $_SESSION["tableparams"][$this->ref]["querytype"]=$this->querytype;
1101                        $_SESSION["tableparams"][$this->ref]["queryjoinclause"]=$this->queryjoinclause;
1102                        $_SESSION["tableparams"][$this->ref]["querysortorder"]=$this->querysortorder;
1103                        $_SESSION["tableparams"][$this->ref]["querywhereclause"]=$this->querywhereclause;
1104
1105                        $_SESSION["tableparams"][$this->ref]["showGroupings"]=$this->showGroupings;
1106
1107                        $_SESSION["tableparams"][$this->ref]["savedfindoptions"]=$this->savedfindoptions;
1108                        $_SESSION["tableparams"][$this->ref]["savedselection"]=$this->savedselection;
1109                        $_SESSION["tableparams"][$this->ref]["savedstartswithfield"]=$this->savedstartswithfield;
1110                        $_SESSION["tableparams"][$this->ref]["savedstartswith"]=$this->savedstartswith;
1111                        $_SESSION["tableparams"][$this->ref]["savedendswith"]=$this->savedendswith;
1112                        $_SESSION["tableparams"][$this->ref]["recordoffset"]=$this->recordoffset;
1113                        $_SESSION["tableparams"][$this->ref]["sqlerror"]=$this->sqlerror;
1114
1115                }
1116
1117                function loadQueryDefaults(){
1118                        //load the defaults from the table definitions
1119                        $this->querywhereclause=$this->subout($this->thetabledef["defaultwhereclause"]);
1120                        $this->querytype=$this->thetabledef["defaultsearchtype"];
1121                        $this->savedfindoptions=$this->thetabledef["defaultcriteriafindoptions"];
1122                        $this->savedselection=$this->thetabledef["defaultcriteriaselection"];
1123                        $this->querysortorder=$this->thetabledef["defaultsortorder"];
1124                }
1125
1126                function resetQuery(){
1127                        // reset query... this requires a call to the function that should be
1128                        // defined in the same place the table parameters are.
1129                        //=====================================================================================================
1130                        $this->querytype="search";
1131                        $this->savedselection="";
1132                        $this->savedstartswithfield="";
1133                        $this->savedstartswith="";
1134                        $this->savedendswith="";
1135                        $this->queryjoinclause="";
1136                        $this->showGroupings = true;
1137
1138                        $this->loadQueryDefaults();
1139                }
1140
1141                function buildSearch($params){
1142
1143                        // assemble Search Criteria
1144                        //=====================================================================================================
1145                        //start with the find pull down
1146                        foreach($this->findoptions as $checkoption){
1147
1148                                if(stripslashes($params["find"])==$checkoption["name"]) {
1149
1150                                        $params["find"]=$checkoption["search"];
1151                                        //keep setting
1152                                        $this->savedfindoptions=$checkoption["name"];
1153
1154                                }//endif
1155
1156                        }//endforeach
1157
1158                        $find = $params["find"];
1159
1160                        //add start with & end with stuff
1161                                if ($params["startswith"]){
1162
1163                                        $params["startswith"]=addslashes($params["startswith"]);
1164
1165                                        //Get the startswithfield info
1166                                        $i=0;
1167                                        while($this->searchablefields[$i]["id"]!=$params["startswithfield"])
1168                                                $i++;
1169
1170                                        if($this->searchablefields[$i]["type"]=="field")
1171                                                $contains=$this->searchablefields[$i]["field"]." like \"".$params["startswith"]."%\"";
1172                                        else
1173                                                $contains=str_replace("{{value}}",$params["startswith"],$this->searchablefields[$i]["field"]);
1174
1175                                        $find= "(".$find.") and (".$contains.")";
1176
1177                                }//endif
1178
1179                        //need to account for add/new/remove
1180                        if(!isset($params["Selection"])) $params["Selection"]="new";
1181                        switch($params["Selection"]){
1182                                case "new":
1183                                        if(!isset($this->querytype)) $this->querytype="";
1184                                        if ($this->querytype!="search") {
1185                                                $this->queryjoinclause="";
1186                                        }
1187                                        $this->querywhereclause=$find;
1188                                break;
1189                                case "add":
1190                                        $this->querywhereclause="(".$this->querywhereclause.") or (".$find.")";
1191                                break;
1192                                case "remove":
1193                                        $this->querywhereclause="(".$this->querywhereclause.") and not (".$find.")";
1194                                break;
1195                                case "narrow":
1196                                        $this->querywhereclause="(".$this->querywhereclause.") and (".$find.")";
1197                                break;
1198                        }
1199
1200                        //keeping settings
1201                        $this->querytype="search";
1202                        $this->savedselection=$params["Selection"];
1203                        $this->savedstartswithfield=$params["startswithfield"];
1204                        $this->savedstartswith=$params["startswith"];
1205
1206                }
1207
1208        }//end class
1209
1210        // SEARCH FUNCTIONS BASE CLASS ======================================================================
1211        class searchFunctions{
1212
1213                var $db;
1214                var $tabledefid;
1215                var $tabledefuuid;
1216                var $idsArray;
1217                var $maintable;
1218                var $deletebutton;
1219
1220                function searchFunctions($db, $tabledefuuid, $idsArray = array()){
1221
1222                        $this->db = $db;
1223                        $this->tabledefuuid = mysql_real_escape_string($tabledefuuid);
1224                        $this->idsArray = $idsArray;
1225
1226                        $querystatement = "
1227                                SELECT
1228                                        id,
1229                                        maintable,
1230                                        deletebutton
1231                                FROM
1232                                        tabledefs
1233                                WHERE
1234                                        uuid = '".$this->tabledefuuid."'";
1235
1236                        $queryresult = $this->db->query($querystatement);
1237
1238                        $therecord = $this->db->fetchArray($queryresult);
1239
1240                        $this->tabledefid = $therecord["id"];
1241
1242                        $this->maintable = $therecord["maintable"];
1243                        $this->deletebutton = $therecord["deletebutton"];
1244
1245                }//end method
1246
1247
1248                function delete_record($useUUID = false){
1249
1250                        if(!$useUUID)
1251                                $whereclause=$this->buildWhereClause();
1252                        else
1253                                $whereclause = $this->buildWhereClause($this->maintable.".uuid");
1254
1255                        $endmessage="";
1256                        switch($this->deletebutton){
1257                                case "inactivate":
1258                                        $querystatement = "UPDATE `".$this->maintable."` SET ".$this->maintable.".inactive = 1, modifiedby = ".$_SESSION["userinfo"]["id"].", modifieddate = NOW() WHERE ".$whereclause;
1259                                        $endmessage=" marked inactive";
1260                                break;
1261                                default:
1262                                case "delete":
1263                                        $querystatement = "DELETE FROM `".$this->maintable."` WHERE ".$whereclause;
1264                                        $endmessage=" deleted";
1265                        }
1266
1267                        $queryresult = $this->db->query($querystatement);
1268                        $message = $this->buildStatusMessage().$endmessage;
1269
1270                        return $message;
1271
1272                }
1273
1274                function buildWhereClause($fieldphrase = NULL ,$idsArray = NULL){
1275                        if($fieldphrase === NULL)
1276                                $fieldphrase = $this->maintable.".id";
1277
1278                        if($idsArray === NULL)
1279                                $idsArray = $this->idsArray;
1280
1281                        $whereclause="";
1282                        foreach($idsArray as $theid){
1283                                $whereclause.=" OR ".$fieldphrase."='".$theid."'";
1284                        }
1285                        $whereclause=substr($whereclause,3);
1286
1287                        return $whereclause;
1288                }
1289
1290                function buildStatusMessage($affected = NULL,$selected = NULL){
1291                        if($affected === NULL)
1292                                $affected = $this->db->affectedRows();
1293
1294                        if($selected === NULL)
1295                                $selected = count($this->idsArray);
1296
1297                        switch($affected){
1298                                case "0":
1299                                        $message="No records";
1300                                break;
1301                                case "1":
1302                                        $message = "1 record";
1303                                break;
1304                                default:
1305                                        $message = $affected." records";
1306                                break;
1307                        }
1308                        if($affected != $selected)
1309                                $message .= " (of ".$selected." selected)";
1310                        return $message;
1311                }
1312
1313                /*
1314                 * function runPush
1315                 * @param string $pushRecordUuid
1316                 */
1317
1318                function runPush($pushRecordUuid) {
1319
1320                        include_once("modules/api/include/push.php");
1321
1322                        $uuidArray = getUuidArray($this->db, $this->tabledefuuid, $this->idsArray);
1323
1324                        if($uuidArray === false)
1325                                $uuidArray = array();
1326
1327                        $push = new push($this->db, $pushRecordUuid, $uuidArray);
1328                        $thereturn = $push->process();
1329
1330                        if($thereturn !== false)
1331                                $message = count($push->uuidArray)." record(s) pushed.";
1332                        else
1333                                $message = "An error has occured.";
1334
1335                        return $message;
1336
1337                }//end function
1338
1339
1340        }//end class
1341
1342
1343//==============================================================================
1344class simpleTable extends displaySearchTable{
1345
1346        var $uniqueName;
1347
1348        function simpleTable($db, $id, $uniqueName){
1349
1350                $this->db = $db;
1351                $this->initialize($id);
1352                $this->uniqueName = $uniqueName;
1353
1354        }//end function simpleTable
1355
1356
1357        function show(){
1358
1359                ?>
1360                <table class="querytable simple" id="<?php echo $this->uniqueName?>" border="0" cellpadding="0" cellspacing="0">
1361
1362                        <thead><?php $this->showHeader()?></thead>
1363
1364                        <tfoot><?php $this->showResultFooter()?></tfoot>
1365
1366                        <tbody>
1367                                <?php
1368                                        if($this->numrows>0)
1369                                                $this->showRecords();
1370                                        else
1371                                                $this->showNoResults();
1372                                ?>
1373                                </tbody>
1374                </table>
1375                <?php
1376
1377
1378        }//end function show
1379
1380
1381        function showHeader(){
1382
1383                ?>
1384                <tr >
1385                        <?php
1386                                foreach ($this->thecolumns as $therow){
1387
1388                                                ?>
1389                                                <th nowrap="nowrap" align="<?php echo $therow["align"]?>" <?php if($therow["size"]) echo 'width="'.$therow["size"].'" ';?> >
1390                                                        <?php echo formatVariable($therow["name"])?>
1391                                                </th>
1392                                                <?php
1393
1394                                }//end foreach
1395                ?></tr><?php
1396
1397        }//end function showHeader
1398
1399
1400        function showRecords(){
1401
1402                $rownum = 1;
1403
1404                $this->db->seek($this->queryresult,0);
1405
1406                //groupings
1407                if($this->showGroupings)
1408                        for($i = 0; $i < count($this->thegroupings); $i++)
1409                                $this->thegroupings[$i]["theValue"]="";
1410
1411                while($therecord = $this->db->fetchArray($this->queryresult)){
1412
1413                        // more groupings
1414                        if($this->showGroupings){
1415
1416                                for($i = 0; $i < count($this->thegroupings); $i++){
1417
1418                                        if($this->thegroupings[$i]["theValue"] != $therecord["_group".($i+1)]){
1419
1420                                                $this->thegroupings[$i]["theValue"] = $therecord["_group".($i+1)];
1421
1422                                                ?><tr class="queryGroup"><td colspan = "<?php echo count($this->thecolumns)?>" <?php if($i) echo 'style = "padding-left:'.($i*15).'px"'?>>
1423                                                <?php
1424                                                        if($this->thegroupings[$i]["displayname"])
1425                                                                echo htmlQuotes($this->thegroupings[$i]["displayname"].": ");
1426                                                        echo $therecord["_group".($i+1)];
1427                                                 ?>
1428                                                </td></tr><?php
1429
1430                                                $rownum = 1;
1431
1432                                        }//endif
1433
1434                                }//endfor
1435
1436                        }//endif
1437
1438                        ?><tr id="<?php echo $this->uniqueName.":".$therecord["theid"];?>" class="qr<?php echo $rownum?>"><?php
1439
1440                                if ($rownum==1)
1441                                        $rownum++;
1442                                else
1443                                $rownum=1;
1444
1445                        foreach($this->thecolumns as $thecolumn){
1446                                ?><td align="<?php echo $thecolumn["align"]?>" <?php if(!$thecolumn["wrap"]) echo "nowrap=\"nowrap\""?>><?php echo (($therecord[$thecolumn["name"]]!=="")?formatVariable($therecord[$thecolumn["name"]],$thecolumn["format"]):"&nbsp;")?></td><?php
1447                        }//endforeach
1448
1449                        ?></tr><?php
1450
1451                }//endwhile
1452
1453        }//end function showRecords;
1454
1455}//end class
1456?>
Note: See TracBrowser for help on using the browser.
Scanned by Orvant Copyright © 2010 Kreotek, LLC. All Rights reserved.