Report.php 33.7 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?php
/***************************************************************
 *  Copyright notice
 *
 *  (c) 2010 Glowbase GmbH <support@glowbase.com>
 *  All rights reserved
 *
 ***************************************************************/

namespace qfq;

//use qfq;

require_once(__DIR__ . '/Define.php');
require_once(__DIR__ . '/Utils.php');
require_once(__DIR__ . '/Variables.php');
require_once(__DIR__ . '/Error.php');
18
19
//require_once(__DIR__ . '/Db.php');
require_once(__DIR__ . '/../Database.php');
20
21
require_once(__DIR__ . '/Link.php');
require_once(__DIR__ . '/Sendmail.php');
22
require_once(__DIR__ . '/../exceptions/UserReportExtension.php');
23
24
25
26


class Report {

Carsten  Rose's avatar
Carsten Rose committed
27
28
29
30
31
    /**
     * @var SIP
     */
    private $sip = null;

32
33
34
35
36
    /**
     * @var Store
     */
    private $store = null;

37
38
39
40
41
42
43
44
45
46
47
    /**
     * @var string
     */
    private $dbAlias = '';
    /**
     * @var Log
     */
    private $log = null;

    // frArray[10.50.5.sql][select ...]
    private $frArray = array();
48

49
50
    // $indexArray[10][50][5]   one entry per 'sql' statement
    private $indexArray = array();
51

52
53
54
55
56
57
58
59
    // TODO to explain
//	private $resultArray = array();
    private $levelCount = 0;
    //private $counter = 0;
    /**
     * @var Variables
     */
    private $variables = null;
60

61
62
63
64
65
66
67
68
69
    /**
     * @var Utils
     */
    private $utils = null;

    /**
     * @var Db
     */
    private $db = null;
70

71
72
73
74
75
76
77
78
79
80
    /**
     * @var Sendmail
     */
    private $sendmail = null;

    private $page_control = array();

    // Emulate global variable: will be set much earlier in other functions. Will be shown in error messages.
    private $fr_error = array('uid' => '', 'pid' => '', 'row' => '', 'debug_level' => '0', 'full_level' => '');

81
    private $t3data = array();
82

83
84
    private $phpUnit = false;

85
86
    private $showDebugInfo = false;

87
    /**
88
     * Report constructor.
89
     *
90
     * @param array $t3data
91
     */
92
93
94
    public function __construct(array $t3data, $sessionName, $phpUnit = false) {

        $this->phpUnit = $phpUnit;
95

96
        $this->t3data = $t3data;
97
        $this->sip = new Sip($sessionName, $phpUnit);
98
        $this->store = Store::getInstance();
99

100
101
        $this->showDebugInfo = ($this->store->getVar(SYSTEM_SHOW_DEBUG_INFO, STORE_SYSTEM) === 'yes');

102
103
104
105
106
107
108
109
110
111
112
113
114
        $this->page_control["msgbox"]["pagec"] = "Please confirm!";

        $this->page_control["hash"]["paged"] = "h";
        $this->page_control["hash"]["pagee"] = "h";
        $this->page_control["hash"]["pagen"] = "h";

        $this->page_control["icon"]["paged"] = "D";
        $this->page_control["icon"]["pagee"] = "E";
        $this->page_control["icon"]["pageh"] = "H";
        $this->page_control["icon"]["pagei"] = "I";
        $this->page_control["icon"]["pagen"] = "N";
        $this->page_control["icon"]["pages"] = "S";

115
116
117
        $this->db = new Database();
        $this->utils = new Utils();
        $this->variables = new Variables($t3data["uid"]);
118

119
        // Set static values, which won't change during this run.
120
        $this->fr_error["pid"] = isset($this->variables->resultArray['global.']['page_id']) ? $this->variables->resultArray['global.']['page_id'] : 0;
121
122
        $this->fr_error["uid"] = $t3data["uid"];
        $this->fr_error["debug_level"] = 0;
123

Carsten  Rose's avatar
Carsten Rose committed
124
        // Sanitize function for POST and GET Parameters.
125
126
127
128
        // Merged URL-Parameter (key1, id etc...) in resultArray.
        $this->variables->resultArray = array_merge($this->variables->resultArray, array("url." => $this->utils->sanitize()),
            array("global." => $this->variables->collectGlobalVariables()));

129
130
        // Create Logclass.
        $this->log = new Log($this->variables->resultArray['global.']);
131

132
133
        // Create sendmail Class. Take care to prepare a fr_log instance.
        $this->sendmail = new Sendmail($this->log);
134
135
136
137
138
139
140
141
    }

    /**
     * Main function. Parses bodytext and iterates over all queries.
     *
     * @return string
     */
    public function process() {
142

143
        $this->log->set_fr_error($this->fr_error);
144

145
        // Iteration over Bodytext
146
        $ttLineArray = explode("\n", $this->t3data['bodytext']);
147

148
149
150
        foreach ($ttLineArray as $index => $line) {
            // Fill $frArray, $indexArray, $resultArray
            $this->parseFRLine($line);
151
        }
152

153
154
155
156
157
158
        // Sort array
        $this->sortIndexArray($this->indexArray, $this->generateSortArg());

        // Report
        $content = $this->triggerReport();

159
        return $content;
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
187
188
189
190
191
192
193
194
195
196
197
198
199

    /**
     * Split line in level, command, content and fill 'frArray', 'levelCount', 'indexArray'
     * Example: 10.50.5.sql = select * from person
     *
     * @param    string $ttLine : line to split in level, command, content
     * @return    void
     */
    private function parseFRLine($ttLine) {

        // 10.50.5.sql = select ...
        $arr = explode("=", trim($ttLine), 2);

        // 10.50.5.sql
        $key = strtolower(trim($arr[0]));

        // comment ?
        if (substr($key, 0, 1) == "#") return;

        // select ...
        $value = trim($arr[1]);

        // 10.50.5.sql
        $arrKey = explode('.', $key);

        // frCmd = "sql"
        $frCmd = $arrKey[count($arrKey) - 1];

        // remove last item (cmd)
        unset($arrKey[count($arrKey) - 1]);

        // save elements only if there is a level specified
        if (count($arrKey)) {
            // level = "10.50.5"
            $level = implode(".", $arrKey);

            // fill Array
            $this->setLine($level, $frCmd, $value);
        }
200
    }
201

202
203
204
205
206
    /**
     * @param $level
     * @param $frCmd
     * @param $value
     */
207
208
209
210
211
212
213
214
215
216
217
218
219
220
    private function setLine($level, $frCmd, $value) {

        // store complete line reformatted in frArray
        $this->frArray[$level . "." . $frCmd] = $value;

        // per sql command
        //pro sql cmd wir der Indexarray abgefüllt. Dieser wird später verwendet um auf den $frArray zuzugreifen
        //if(preg_match("/^sql/i", $frCmd) == 1){
        if ($frCmd == "sql" || $frCmd == "form") {
            // Remember max level
            $this->levelCount = max(substr_count($level, '.') + 1, $this->levelCount);
            // $indexArray[10][50][5]
            $this->indexArray[] = explode(".", $level);
        }
221
    }
222
223
224
225

    /**
     * Sorts the associative array.
     *
226
227
     * @param    array $ary : The unsorted Level Array
     * @param    string $clause : the sort argument 0 ASC, 1 ASC... according to the number of columns
228
229
     * @return    The content that is displayed on the website
     */
230
    private function sortIndexArray(array &$ary, $clause, $ascending = true) {
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276

        $clause = str_ireplace('order by', '', $clause);
        $clause = preg_replace('/\s+/', ' ', $clause);
        $keys = explode(',', $clause);
        $dirMap = array('desc' => 1, 'asc' => -1);
        $def = $ascending ? -1 : 1;

        $keyAry = array();
        $dirAry = array();
        foreach ($keys as $key) {
            $key = explode(' ', trim($key));
            $keyAry[] = trim($key[0]);
            if (isset($key[1])) {
                $dir = strtolower(trim($key[1]));
                $dirAry[] = $dirMap[$dir] ? $dirMap[$dir] : $def;
            } else {
                $dirAry[] = $def;
            }
        }
        $fnBody = '';
        for ($i = count($keyAry) - 1; $i >= 0; $i--) {
            $k = $keyAry[$i];
            $t = $dirAry[$i];
            $f = -1 * $t;
            $aStr = '$a[\'' . $k . '\']';
            $bStr = '$b[\'' . $k . '\']';

            if (strpos($k, '(') !== false) {
                $aStr = '$a->' . $k;
                $bStr = '$b->' . $k;
            }

            if ($fnBody == '') {
                $fnBody .= "if({$aStr} == {$bStr}) { return 0; }\n";
                $fnBody .= "return ({$aStr} < {$bStr}) ? {$t} : {$f};\n";
            } else {
                $fnBody = "if({$aStr} == {$bStr}) {\n" . $fnBody;
                $fnBody .= "}\n";
                $fnBody .= "return ({$aStr} < {$bStr}) ? {$t} : {$f};\n";
            }
        }

        if ($fnBody) {
            $sortFn = create_function('$a,$b', $fnBody);
            usort($ary, $sortFn);
        }
277
    }
278

279
280
281
282
283
    /**
     * generateSortArg
     *
     * @return string
     */
284
285
286
287
288
289
290
291
292
    private function generateSortArg() {

        $sortArg = "";

        for ($i = 0; $i < $this->levelCount; $i++) {
            $sortArg = $sortArg . $i . " ASC, ";
        }
        $sortArg = substr($sortArg, 0, strlen($sortArg) - 2);
        return $sortArg;
293
    }
294
295
296
297
298
299
300
301
302
303
304
305
306
307

    /**
     * Executes the queries recursive. This Method is called for each Sublevel.
     *
     * ROOTLEVEL
     * This method is called once from the main method.
     * For the first call the method executes the rootlevels
     *
     * SUBLEVEL
     * For each rootlevel the method calls it self whith the levelmode 0
     * If the next Level is a Sublevel it will be executed and $this->counter will be added by 1
     * The sublevel calls the method again for a following sublevel
     *
     * @param int $cur_level Which level it will call [10] = level 1, [10.10] = level 2 ...
308
309
     * @param string $super_level_array The Value-Array of the indexarray [0=>10, 1=>50]
     * @param int $counter The outer numeric Arraykey of indexarray
310
311
312
313
314
315
316
     * @return string                       The content that is displayed on the website
     * @throws codeException
     * @throws SqlReportException
     * @throws SyntaxReportException
     * @throws UserReportException
     */

317
318
    private function triggerReport($cur_level = 1, array $super_level_array = array(), $counter = 0) {
        $keys = array();
319
320
321
322
323
324

        $lineDebug = 0;
        $content = "";
        $rowTotal = 0;

        // CurrentLevel "10.10.50"
325
326
327
328
329
330
        if (isset($this->indexArray[$counter]) && is_array($this->indexArray[$counter])) {
            $full_level = implode(".", $this->indexArray[$counter]);
        } else {
            $full_level = '';
        }

331
        // Superlevel "10.10"
332
333
334
335
336
        if (isset($super_level_array) && is_array($super_level_array)) {
            $full_super_level = implode(".", $super_level_array);
        } else {
            $full_super_level = '';
        }
337
338
339
340
341
342
343

        //condition1: indexArray
        //condition2: full_level == Superlevel (but at the length of the Superlevel)
        while ($counter < count($this->indexArray) && $full_super_level == substr($full_level, 0, strlen($full_super_level))) {

            //True: The cur_level is a subquery -> continue
            if ($cur_level != count($this->indexArray[$counter])) {
344
345
346
347
348
349
                ++$counter;
                if (isset($this->indexArray[$counter]) && is_array($this->indexArray[$counter])) {
                    $full_level = implode(".", $this->indexArray[$counter]);
                } else {
                    $full_level = '';
                }
350
351
352
353
                continue;
            }

            // Set dbAlias if one is specified. Else keep the parent one.
354
355
            //TODO dbAlias
//            $this->dbAlias = $this->getValueParentDefault("db", $full_super_level, $full_level, $cur_level, DB);
356
357
358
359
360

            // Set debug, if one is specified else keep the parent one.
            $lineDebug = $this->getValueParentDefault("debug", $full_super_level, $full_level, $cur_level, 0);

            // Prepare Error reporting
361
362
            $this->store->setVar(SYSTEM_SQL_RAW, $this->frArray[$full_level . ".sql"], STORE_SYSTEM);
            $this->store->setVar(SYSTEM_REPORT_FULL_LEVEL, $full_level, STORE_SYSTEM);
363

364
365
366
            // Prepare SQL: replace variables. Actual 'line.total' or 'line.count' will recalculated: don't replace them now!
            unset($this->variables->resultArray[$full_level . ".line."]["total"]);
            unset($this->variables->resultArray[$full_level . ".line."]["count"]);
367
368
            $sql = $this->variables->doVariables($this->frArray[$full_level . ".sql"]);

369
            $this->store->setVar(SYSTEM_SQL_FINAL, $sql, STORE_SYSTEM);
370
371
372

            //Execute SQL. All errors have been already catched.
            unset($result);
373
            $result = $this->db->sqlKeys($sql, $keys);
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397

            // If an array is returned, $sql was a query, otherwise an 'insert', 'update', 'delete', ...
            // Query: total nummber of rows
            // insert: last_insert_id
            // delete, update: number of affected rows
            $rowTotal = is_array($result) ? count($result) : $result;

            $this->variables->resultArray[$full_level . ".line."]["total"] = $rowTotal;

            // HEAD: If there is at least one record, do 'head'.
            if ($rowTotal > 0)
                $content .= $this->variables->doVariables($this->frArray[$full_level . "." . "head"]);

            // Prepare row alteration
            $arrRbgd = explode("|", $this->frArray[$full_level . "." . "rbgd"]);

            //---------------------------------
            // Process each row of resultset
            $columnValueSeperator = "";
            $rowIndex = 0;
            foreach ($result as $row) {
                // record number counter
                $this->variables->resultArray[$full_level . ".line."]["count"] = ++$rowIndex;

398
                // replace {{<level>.line.count}} and {{<level>.line.total}} in __result__, if the variables specify their own full_level. This can't be replaced before firing the query.
399
                for ($ii = 0; $ii < count($row); $ii++) {
400
401
                    $row[$ii] = str_replace("{{" . $full_level . ".line.count}}", $rowIndex, $row[$ii]);
                    $row[$ii] = str_replace("{{" . $full_level . ".line.total}}", $rowTotal, $row[$ii]);
402
403
404
405
                }

                // SEP set seperator (empty on first run)
                $content .= $columnValueSeperator;
406
                $columnValueSeperator = $this->variables->doVariables($this->frArray[$full_level . "." . "rsep"]);
407

408
                // RBGD: even/odd rows
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
                $content .= str_replace("rbgd", $arrRbgd[$rowIndex % 2], $this->frArray[$full_level . "." . "rbeg"]);

                //-----------------------------
                // COLUMNS: Collect all columns
                $content .= $this->collectRow($row, $keys, $full_level, $rowIndex);

                // REND
                $content .= $this->variables->doVariables($this->frArray[$full_level . "." . "rend"]);

                // Trigger subqueries of this level
                $content .= $this->triggerReport($cur_level + 1, $this->indexArray[$counter], $counter + 1);

                // RENR
                $content .= $this->variables->doVariables($this->frArray[$full_level . "." . "renr"]);

            }

            //Print althead or tail
            if ($rowTotal > 0) {
                $content .= $this->variables->doVariables($this->frArray[$full_level . "." . "tail"]);
            } else {
                $content .= $this->variables->doVariables($this->frArray[$full_level . "." . "althead"]);
            }

433
434
435
436
437
438
            ++$counter;
            if (isset($this->indexArray[$counter]) && is_array($this->indexArray[$counter])) {
                $full_level = implode(".", $this->indexArray[$counter]);
            } else {
                $full_level = '';
            }
439
440
441
        }

        return $content;
442
    }
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471

    /**
     * Determine value:
     * 1) if one specified in line: take it
     * 2) if one specified in upper level: take it
     * 3) if none above take default
     * Set value on $full_level
     *
     * @param    string $level_key - 'db' or 'debug'
     * @param    string $full_super_level - f.e.: 10.10.
     * @param    string $full_level - f.e.: 10.10.10.
     * @param    string $cur_level - f.e.: 2
     * @param    string $default - f.e.: 0
     * @return   string  The calculated value.
     */
    private function getValueParentDefault($level_key, $full_super_level, $full_level, $cur_level, $default) {

        if ($this->frArray[$full_level . "." . $level_key]) {
            $value = $this->frArray[$full_level . "." . $level_key];
        } else {
            if ($cur_level == 1) {
                $value = $default;
            } else {
                $value = $this->variables->resultArray[$full_super_level . ".line."][$level_key];
            }
        }
        $this->variables->resultArray[$full_level . ".line."][$level_key] = $value;

        return ($value);
472
    }
473
474
475
476
477
478
479
480
481
482
483
484
485
486

    /**
     * Steps through 'row' and collects all columns
     *
     * @param array $row Recent row fetch from sql resultset.
     * @param array $keys List of all columnnames
     * @param string $full_level Recent position to work on.
     * @param string $rowIndex Index of recent row in resultset.
     * @return string               Collected content of all printable columns
     * @throws SyntaxReportException
     */
    private function collectRow(array $row, array $keys, $full_level, $rowIndex) {
        $content = "";

487
        $fsep = '';
488
489
        for ($ii = 0; $ii < count($keys); $ii++) {

490
491
492
            $this->store->setVar(SYSTEM_REPORT_COLUMN_INDEX, $ii + 1, STORE_SYSTEM);
            $this->store->setVar(SYSTEM_REPORT_COLUMN_NAME, $keys[$ii], STORE_SYSTEM);
            $this->store->setVar(SYSTEM_REPORT_COLUMN_VALUE, $row[$ii], STORE_SYSTEM);
493
494
495
496

            $tmp = $this->renderColumn($ii, $keys[$ii], $row[$ii], $full_level, $rowIndex, $show);
            if ($show) {
                //prints
497
                $content .= $this->variables->doVariables($fsep);
498
499
500
                $content .= $this->variables->doVariables($this->frArray[$full_level . "." . "fbeg"]);
                $content .= $tmp;
                $content .= $this->variables->doVariables($this->frArray[$full_level . "." . "fend"]);
501
                $fsep = $this->frArray[$full_level . "." . "fsep"];
502
503
504
            }
        }
        return ($content);
505
    }
506
507
508
509

    /**
     * Renders column depending of column name (if name is a reserved column name)
     *
510
511
512
513
514
515
516
517
     * @param string $columnIndex
     * @param string $columnName
     * @param string $columnValue
     * @param string $full_level
     * @param string $rowIndex
     * @param bool $show
     * @return string rendered column
     * @throws SyntaxReportException
518
519
     */
    private function renderColumn($columnIndex, $columnName, $columnValue, $full_level, $rowIndex, &$show) {
520

521
522
        $show = TRUE;
        if (substr($columnName, 0, 1) == "_") {
523
            $show = false;
524
525
526
527
528
529
            $columnName = substr($columnName, 1);
        }

        $content = "";
        switch ($columnName) {
            case "link":
530
531
                $link = new Link($this->fr_error, $this->dbAlias, $this->sip);
                $content .= $link->renderLink($columnValue);
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
#				unset $link;
                break;
            case "exec":
                $content .= $this->myExec($columnValue);
                break;

            case "Page":
            case "Pagec":
            case "Paged":
            case "Pagee":
            case "Pageh":
            case "Pagei":
            case "Pagen":
            case "Pages":
                $linkValue = $this->doFixColPosPage($columnName, $columnValue);

548
549
            $link = new Link($this->fr_error, $this->sip);
            $content .= $link->renderLink($linkValue);
550
551
552
553
554
555
556
557
558
559
560
561
562
563
                break;

            case "page":
            case "pagec":
            case "paged":
            case "pagee":
            case "pageh":
            case "pagei":
            case "pagen":
            case "pages":
#debug($columnValue);
                $linkValue = $this->doPage($columnName, $columnValue);
// debug($linkValue);

564
565
            $link = new Link($this->fr_error, $this->sip);
            $content .= $link->renderLink($linkValue);
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
                break;

            case "img":
                // "<path to image>|[alttext]|[text behind]" renders to: <img src="<path to image>" alt="[alttext]">[text behind]
                if (empty($columnValue)) break;
                $tmp = explode("|", $columnValue, 3);
                if ($tmp[0] == "") break;
                $content .= '<img src="' . $tmp[0] . '" alt="' . $tmp[1] . '">' . $tmp[2];
                break;

            case "mailto":
                // "<email address>|[Real Name]"  renders to (encrypted via JS): <a href="mailto://<email address>"><email address></a> OR <a href="mailto://<email address>">[Real Name]</a>
                $tmp = explode("|", $columnValue, 2);
                if ($tmp[0] == "") break;

                $t1 = explode("@", $tmp[0], 2);
                $content .= "<script language=javascript><!--" . chr(10);
                if (empty($tmp[1])) $tmp[1] = $tmp[0];

                $content .= 'var contact = "' . substr($tmp[1], 0, 2) . '"' . chr(10);
                $content .= 'var contact1 = "' . substr($tmp[1], 2) . '"' . chr(10);
                $content .= 'var email = "' . $t1[0] . '"' . chr(10);
                $content .= 'var emailHost = "' . $t1[1] . '"' . chr(10);

                $content .= 'document.write("<a href=" + "mail" + "to:" + email + "@" + emailHost+ ">" + contact + "</a>")' . chr(10);
                $content .= 'document.write("<a href=" + "mail" + "to:" + email + "@" + emailHost+ ">" + contact1 + "</a>")' . chr(10);
                $content .= '//--></script>';
                break;

            case "sendmail":
                // 'Absender|Empfaenger, mehrere mit Komma getrennt|Betreff|Mailinhalt'
                $tmp = explode("|", $columnValue, 4);

                $mail['receiver'] = $tmp[0];
                $mail['sender'] = $tmp[1];
                $mail['subject'] = $tmp[2];
                $mail['body'] = $tmp[3];

                $content = $this->sendmail->sendmail($mail);
                break;

            case "vertical":
                // '<Text>|[angle]|[width]|[height]|[tag]'   , width and heigth needs a unit (px, em ,...), 'tag' might be 'div', 'span', ...
                $arr = explode("|", $columnValue, 5);

                # angle
                $angle = $arr[1] ? $arr[1] : 270;

                # width
                $width = $arr[2] ? $arr[2] : "1em";
                $tmp = "width:$width; ";

                # height
                if ($arr[3])
                    $tmp .= "height:" . $arr[3] . "; ";

                # tag
                if ($arr[4]) {
                    $tag = explode(" ", trim($arr[4]), 2);
                    $tag_open = "<" . $arr[4] . " ";
                    $tag_close = "</" . $tag[0] . ">";
                } else {
                    $tag_open = "<div ";
                    $tag_close = "</div>";
                }

                # http://scottgale.com/blog/css-vertical-text/2010/03/01/
                #$style = "writing-mode:tb-rl; -webkit-transform:rotate(270deg); -moz-transform:rotate(270deg); -o-transform: rotate(270deg); white-space:nowrap; width:1em;  display: block;";
                $style = "width:1em;  filter: flipv fliph; transform: rotate(" . $angle . "deg) translate(-10em,0); transform-origin: 0 0; writing-mode:tb-rl; -webkit-transform:rotate(" . $angle . "deg); -moz-transform:rotate(" . $angle . "deg); -o-transform: rotate(" . $angle . "deg); white-space:nowrap; display: block;";

                #$style = "line-height: 1.5em; background:#eee; display: block; white-space: nowrap; padding-left: 3px; writing-mode: tb-rl; filter: flipv fliph; transform: rotate(270deg) translate(-10em,0); transform-origin: 0 0; -moz-transform: rotate(270deg) translate(-10em,0); -moz-transform-origin: 0 0; -webkit-transform: rotate(270deg) translate(-10em,0); -webkit-transform-origin: 0 0;";
                $content = $tag_open . 'style="' . $style . '">' . $arr[0] . $tag_close;


                break;

            case "F":
                $newColumnName = "";
                $newFinalColumnName = "";
                $remain = array();
646
                $striptags = false;
647
648
649
650
651
652
653
654
655
656
657
658
659
                $tag = "";

                # 'Q:mailto|Z|V:mail_first|support@example.com'
                $arr = explode("|", $columnValue);
                foreach ($arr as $value) {
                    $kv = explode(":", $value);
                    switch ($kv[0]) {
                        case "Q":
                            $newColumnName = $kv[1];
                            #if(!$newColumnName) throw new syntaxException ( "Missing a 'reserved column name' for parameter 'Q' in column 'F': $columnValue","",__FILE__,__LINE__,$this->fr_error);
                            if ($newColumnName == 'F') throw new SyntaxReportException ("Not allowed: 'F' as 'reserved column name' for parameter 'Q': $columnValue", "", __FILE__, __LINE__, $this->fr_error);
                            break;
                        case "Z":
660
                            $show = false;
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
                            break;
                        case "T":
                            $striptags = TRUE;
                            break;
                        case "X":
                            $tag = $kv[1];
                            if (!$tag) throw new SyntaxReportException ("Missing the 'tag' parameter for 'X'):  $columnValue", "", __FILE__, __LINE__, $this->fr_error);
                            break;
                        case "V":
                            $newFinalColumnName = $kv[1];
                            if (!$newFinalColumnName) throw new SyntaxReportException ("Missing the 'name' parameter for 'V':  $columnValue", "", __FILE__, __LINE__, $this->fr_error);
                            break;
                        case 'F':
                            throw new SyntaxReportException ("Qualifier 'F' is not allowed inside of a column with column name 'F':  $columnValue", "", __FILE__, __LINE__, $this->fr_error);
                            break;
                        # Save every non 'F' qualifier for later usage
                        default:
                            $remain[] = $value;
                            break;
                    }
                }
                # Check for needed action
                #			if(!$newColumnName) throw new syntaxException ( "Missing parameter 'Q' in column 'F': $columnValue","",__FILE__,__LINE__,$this->fr_error);
                if ($newColumnName)
                    $columnName = $newColumnName;
                else
                    $columnName = "no column name defined";

                # reconstruct remaining parameters
                $arr = implode("|", $remain);
                # render
                $content = $this->renderColumn($columnIndex, $columnName, $arr, $full_level, $rowIndex, $dummy);

                if ($newFinalColumnName)
                    $columnName = $newFinalColumnName;

                # striptags
                if ($striptags) $content = strip_tags($content);
                # tag
                if ($tag) {
                    $arr = explode(" ", $tag);
                    $content = "<" . $tag . ">" . $content . "</" . $arr[0] . ">";
                }
                break;

            default :
                $content .= $columnValue;
                break;
        }
        $this->variables->resultArray[$full_level . "."][$columnName] = $content;

        return $content;
713
    }
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730

    /**
     * Executes the Command in $cmd
     * RC: if RC==0 Returns Output, else 'RC - Output'
     *
     * @param    string $cmd : contains the Comand
     * @return   string  The content that is displayed on the website
     */
    private function myExec($cmd) {

        exec($cmd, $arr, $rc);

        $output = implode('<BR>', $arr);
        if ($rc != 0)
            $output = $rc . " - " . $output;

        return ($output);
731
    }
732
733
734
735
736
737

    /**
     * The main method of the PlugIn
     *
     * @param    string $content : The PlugIn content
     * @param    array $conf : The PlugIn configuration
Carsten  Rose's avatar
Carsten Rose committed
738
     * @return    string The content that is displayed on the website
739
     */
Carsten  Rose's avatar
Carsten Rose committed
740
741
742
    //Checkt ob der Beginn von Array2 gleich ist wie Array1
    // gibt true/false zurück

743
744
745
746
747
748
749
750
751
752
753
    /**
     * Renders PageX: convert position content to token content. Respect default values depending on PageX
     *
     * @param    string $columnName
     * @param    string $columnValue
     * @return string rendered link
     *
     * $columnValue:
     * -------------
     * [<page id|alias>[&param=value&...]] | [record id] | [text] | [tooltip] | [msgbox] | [class] | [target] | [render mode] | [create hash]
     *
754
     * param[0]: <page id|alias>[&param=value&...]
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
     * param[1]: record id
     * param[2]: text
     * param[3]: tooltip
     * param[4]: msgbox
     * param[5]: class
     * param[6]: target
     * param[7]: render mode
     * param[8]: create hash
     * @throws SyntaxReportException
     */
    private function doFixColPosPage($columnName, $columnValue) {

        $link = "";

        // Split definition
        $param = explode('|', $columnValue);
771
772
        if (count($param) > 9)
            throw new SyntaxReportException ("Too many parameter (max=9): $columnValue", "", __FILE__, __LINE__, $this->fr_error);
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793

        // make first 'P' lowercase
        $columnName = 'p' . substr($columnName, 1);

        // -- Page --
        // Split PageId|PageAlias and  URL Params
        $tmparr = explode('&', $param[0], 2);

        $link .= $this->composeLinkPart('p', $tmparr[0]);            // -- PageID --
        $link .= $this->composeLinkPart('U', $tmparr[1]);            // -- URL Params --
        $link .= $this->composeLinkPart('i', $param[1]);                // -- record id --
        $link .= $this->composeLinkPart('t', $param[2]);                // -- Text --
        $link .= $this->composeLinkPart('o', $param[3]);                // -- tooltip --
        $link .= $this->composeLinkPart('q', $param[4], $this->page_control["msgbox"][$columnName]);                // -- msgbox
        $link .= $this->composeLinkPart('c', $param[5]);                // -- class --
        $link .= $this->composeLinkPart('g', $param[6]);                // -- target --
        $link .= $this->composeLinkPart('r', $param[7]);                // -- render mode --

        if (!$param[8]) $param[8] = $this->page_control["hash"][$columnName]; // if no hash behaviour defined, use default
        if ($param[8] == "h") $link .= "h|";

794
795
        if ($this->page_control["icon"][$columnName])
            $link .= $this->page_control["icon"][$columnName] . "|";
796
797

        return ($link);
798
    }
799

Carsten  Rose's avatar
Carsten Rose committed
800
801
802
803
804
805
806
807
808
    /**
     * The main method of the PlugIn
     *
     * @param    string $content : The PlugIn content
     * @param    array $conf : The PlugIn configuration
     * @return   string The content that is displayed on the website
     */
    //Check ob arr1 nur 1 Feld mehr hat als arr2

809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
    /**
     * If there is a value (or a defaultValue): compose it together with qualifier and delimiter.
     *
     * @param    string $qualifier
     * @param    string $value
     * @param    string $defaultValue
     *
     * @return    string        rendered link
     */
    private function composeLinkPart($qualifier, $value, $defaultValue = "") {

        if (!$value) $value = $defaultValue;

        if ($value)
            return ($qualifier . ":" . $value . "|");

        return '';
826
    }
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878

    /**
     * Renders pageX: extract token and determine if any default value has be applied
     *
     * @param    string $columnName
     * @param    string $columnValue
     *
     * @return    string        rendered link
     */
    private function doPage($columnName, $columnValue) {
        $defaultQuestion = '';

        $param = explode('|', $columnValue);

        # get all defaultvalues, depending on the columnname
        $defaultImage = $this->page_control["icon"][$columnName];
        $defaultHash = $this->page_control["hash"][$columnName];
        # define defaultquestion only, if pagetype needs a question
        if ($this->page_control["msgbox"][$columnName]) $defaultQuestion = 'q:' . $this->page_control["msgbox"][$columnName];

        foreach ($param as $key) {
            switch (substr($key, 0, 1)) {
                case 'P':
                case 'E':
                case 'N':
                case 'D':
                case 'H':
                case 'I':
                case 'S':
                case 'B':
                case 'C':
                    $defaultImage = '';    // if any of the img token is given: no default
                    break;
                case 'h':
                    $defaultHash = '';    // if a hash definition is given: no default
                    break;
                case 'q':
                    $defaultQuestion = '';    // if a question is given: no default
                    break;
            }
        }

        $columnValue .= "|";

        // append defaulst
        if ($defaultImage) $columnValue .= $defaultImage . "|";
        if ($defaultHash) $columnValue .= $defaultHash . "|";
        if ($defaultQuestion) $columnValue .= $defaultQuestion . "|";

#debug($columnValue);

        return ($columnValue);
879
    }
880

Carsten  Rose's avatar
Carsten Rose committed
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
    /**
     * Prepare Session Array with Hash Entry: Only for form
     *
     * @param $formName
     * @param $formRecordId
     * @return string
     */
    private function form2hash($formName, $formRecordId) {
        $hash = $this->utils->randomAlphaNumUnique();

        $_SESSION[FORMREPORT][$hash]['formName'][0] = $formName;
        $_SESSION[FORMREPORT][$hash]['referrer'] = $_SERVER['REQUEST_URI'];

        if (is_numeric($formRecordId) && $formRecordId >= 0) {
            $_SESSION[FORMREPORT][$hash]['idMap'][1]['recordId'] = $formRecordId;
            $_SESSION[FORMREPORT][$hash]['idMap'][1]['param'] = "";
        }

        return ($hash);
    }

902
903
904
    /**
     * Generate SortArgument
     *
905
906
     * @param $variable
     * @return string
907
908
909
910
911
912
     */
    private function getResultArrayIndex($variable) {

        $variable = substr($variable, 1, strlen($variable));
        return "[" . preg_replace_callback("/[a-z]/", "replaceToIndex", $variable) . "][" . preg_replace_callback("/[^a-z]/", "replaceToIndex", $variable) . "]";

913
    }
914

915
916
917
918
919
    /**
     * @param $arr1
     * @param $arr2
     * @return bool
     */
920
921
922
923
924
925
926
927
    private function compareArraystart($arr1, $arr2) {

        for ($i = 0; $i < count($arr1); $i++) {
            if ($arr1[$i] != $arr2[$i]) {
                return false;
            }
        }
        return true;
928
    }
929

930
931
932
933
934
    /**
     * @param $arr1
     * @param $arr2
     * @return bool
     */
935
936
937
938
939
940
    private function compareArraylength($arr1, $arr2) {

        if (count($arr1) + 1 == count($arr2)) {
            return true;
        }
        return false;
941
942
    }
}