PageRenderTime 895ms CodeModel.GetById 189ms app.highlight 356ms RepoModel.GetById 106ms app.codeStats 4ms

/components/com_breezingforms/facileforms.process.php

https://bitbucket.org/izubizarreta/https-bitbucket.org-bityvip-alpes
PHP | 6664 lines | 5891 code | 594 blank | 179 comment | 1593 complexity | 4bbee968557cf120285e4689635c3aae MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   1<?php
   2
   3/**
   4 * BreezingForms - A Joomla Forms Application
   5 * @version 1.8
   6 * @package BreezingForms
   7 * @copyright (C) 2008-2012 by Markus Bopp
   8 * @license Released under the terms of the GNU General Public License
   9 * */
  10defined('_JEXEC') or die('Direct Access to this location is not allowed.');
  11
  12class bfMobile {
  13    public $isMobile = false;
  14}
  15
  16$mainframe = JFactory::getApplication();
  17
  18$ff_processor = null;
  19
  20define('_FF_PACKBREAKAFTER', 250);
  21
  22define('_FF_STATUS_OK', 0);
  23define('_FF_STATUS_UNPUBLISHED', 1);
  24define('_FF_STATUS_SAVERECORD_FAILED', 2);
  25define('_FF_STATUS_SAVESUBRECORD_FAILED', 3);
  26define('_FF_STATUS_UPLOAD_FAILED', 4);
  27define('_FF_STATUS_SENDMAIL_FAILED', 5);
  28define('_FF_STATUS_ATTACHMENT_FAILED', 6);
  29define('_FF_STATUS_CAPTCHA_FAILED', 7);
  30define('_FF_STATUS_FILE_EXTENSION_NOT_ALLOWED', 8);
  31
  32define('_FF_DATA_ID', 0);
  33define('_FF_DATA_NAME', 1);
  34define('_FF_DATA_TITLE', 2);
  35define('_FF_DATA_TYPE', 3);
  36define('_FF_DATA_VALUE', 4);
  37define('_FF_DATA_FILE_SERVERPATH', 5);
  38
  39define('_FF_IGNORE_STRICT', 1);
  40define('_FF_TRACE_NAMELIMIT', 100);
  41
  42// tracemode bits
  43define('_FF_TRACEMODE_EVAL', 8);
  44define('_FF_TRACEMODE_PIECE', 16);
  45define('_FF_TRACEMODE_FUNCTION', 32);
  46define('_FF_TRACEMODE_MESSAGE', 64);
  47define('_FF_TRACEMODE_LOCAL', 128);
  48define('_FF_TRACEMODE_DIRECT', 256);
  49define('_FF_TRACEMODE_APPEND', 512);
  50define('_FF_TRACEMODE_DISABLE', 1024);
  51define('_FF_TRACEMODE_FIRST', 2048);
  52
  53// tracemode masks
  54define('_FF_TRACEMODE_PRIORITY', 7);
  55define('_FF_TRACEMODE_TOPIC', 120);
  56define('_FF_TRACEMODE_VARIABLE', 248);
  57
  58// debugging flags
  59define('_FF_DEBUG_PATCHEDCODE', 1);
  60define('_FF_DEBUG_ENTER', 2);
  61define('_FF_DEBUG_EXIT', 4);
  62define('_FF_DEBUG_DIRECTIVE', 8);
  63define('_FF_DEBUG', 0);
  64
  65function ff_trace($msg = null) {
  66    global $ff_processor;
  67
  68    if ($ff_processor->dying ||
  69            ($ff_processor->traceMode & _FF_TRACEMODE_DISABLE) ||
  70            !($ff_processor->traceMode & _FF_TRACEMODE_MESSAGE))
  71        return;
  72    $level = count($ff_processor->traceStack);
  73    $trc = '';
  74    for ($l = 0; $l < $level; $l++)
  75        $trc .= '  ';
  76    $trc .= BFText::_('COM_BREEZINGFORMS_PROCESS_MSGUNKNOWN') . ": $msg\n";
  77    $ff_processor->traceBuffer .= htmlspecialchars($trc, ENT_QUOTES);
  78    if ($ff_processor->traceMode & _FF_TRACEMODE_DIRECT)
  79        $ff_processor->dumpTrace();
  80}
  81
  82// ff_trace
  83
  84function _ff_trace($line, $msg = null) {
  85    global $ff_processor;
  86
  87    // version for patched code
  88    if ($ff_processor->dying || ($ff_processor->traceMode & _FF_TRACEMODE_DISABLE))
  89        return;
  90    $level = count($ff_processor->traceStack);
  91    if ($msg && ($ff_processor->traceMode & _FF_TRACEMODE_MESSAGE)) {
  92        $trc = '';
  93        for ($l = 0; $l < $level; $l++)
  94            $trc .= '  ';
  95        $trc .= BFText::_('COM_BREEZINGFORMS_PROCESS_LINE') . " $line: $msg\n";
  96        $ff_processor->traceBuffer .= htmlspecialchars($trc, ENT_QUOTES);
  97        if ($ff_processor->traceMode & _FF_TRACEMODE_DIRECT)
  98            $ff_processor->dumpTrace();
  99    } // if
 100    if ($level)
 101        $ff_processor->traceStack[$level - 1][3] = $line;
 102}
 103
 104// _ff_trace
 105
 106function _ff_getMode(&$newmode, &$name) {
 107    global $ff_processor;
 108
 109    $oldmode = $ff_processor->traceMode;
 110    if (_FF_DEBUG & _FF_DEBUG_ENTER)
 111        $ff_processor->traceBuffer .=
 112                htmlspecialchars(
 113                "\n_FF_DEBUG_ENTER:" .
 114                "\n  Name              = $name" .
 115                "\n  Old mode before   = " . $ff_processor->dispTraceMode($oldmode) .
 116                "\n  New mode before   = " . $ff_processor->dispTraceMode($newmode), ENT_QUOTES
 117        );
 118    if (is_null($newmode) || ($newmode & _FF_TRACEMODE_PRIORITY) < ($oldmode & _FF_TRACEMODE_PRIORITY)) {
 119        $newmode = $oldmode;
 120        $ret = $oldmode;
 121    } else {
 122        $newmode = ($oldmode & ~_FF_TRACEMODE_VARIABLE) | ($newmode & _FF_TRACEMODE_VARIABLE);
 123        if ($oldmode != $newmode)
 124            $ff_processor->traceMode = $newmode;
 125        $ret = ($newmode & _FF_TRACEMODE_LOCAL) ? $oldmode : $newmode;
 126    } // if
 127    if (_FF_DEBUG & _FF_DEBUG_ENTER) {
 128        $ff_processor->traceBuffer .=
 129                htmlspecialchars(
 130                "\n  Old mode compiled = " . $ff_processor->dispTraceMode($ret) .
 131                "\n  New mode compiled = " . $ff_processor->dispTraceMode($newmode) .
 132                "\n", ENT_QUOTES
 133        );
 134        if ($ff_processor->traceMode & _FF_TRACEMODE_DIRECT)
 135            $ff_processor->dumpTrace();
 136    } // if
 137    return $ret;
 138}
 139
 140// _ff_getmode
 141
 142function _ff_tracePiece($newmode, $name, $line, $type, $id, $pane) {
 143    global $ff_processor;
 144
 145    if ($ff_processor->dying || ($ff_processor->traceMode & _FF_TRACEMODE_DISABLE))
 146        return;
 147    $oldmode = _ff_getMode($newmode, $name);
 148    if ($newmode & _FF_TRACEMODE_PIECE) {
 149        $level = count($ff_processor->traceStack);
 150        for ($l = 0; $l < $level; $l++)
 151            $ff_processor->traceBuffer .= '  ';
 152        $ff_processor->traceBuffer .=
 153                htmlspecialchars(
 154                "+" . BFText::_('COM_BREEZINGFORMS_PROCESS_ENTER') . " $name " . BFText::_('COM_BREEZINGFORMS_PROCESS_ATLINE') . " $line\n", ENT_QUOTES
 155        );
 156        if ($ff_processor->traceMode & _FF_TRACEMODE_DIRECT)
 157            $ff_processor->dumpTrace();
 158    } // if
 159    array_push($ff_processor->traceStack, array($oldmode, 'p', $name, $line, $type, $id, $pane));
 160}
 161
 162// _ff_tracePiece
 163
 164function _ff_traceFunction($newmode, $name, $line, $type, $id, $pane, &$args) {
 165    global $ff_processor;
 166
 167    if ($ff_processor->dying || ($ff_processor->traceMode & _FF_TRACEMODE_DISABLE))
 168        return;
 169    $oldmode = _ff_getMode($newmode, $name);
 170    if ($newmode & _FF_TRACEMODE_FUNCTION) {
 171        $level = count($ff_processor->traceStack);
 172        $trc = '';
 173        for ($l = 0; $l < $level; $l++)
 174            $trc .= '  ';
 175        $trc .= "+" . BFText::_('COM_BREEZINGFORMS_PROCESS_ENTER') . " $name(";
 176        if ($args) {
 177            $next = false;
 178            foreach ($args as $arg) {
 179                if ($next)
 180                    $trc .= ', '; else
 181                    $next = true;
 182                if (is_null($arg))
 183                    $trc .= 'null';
 184                else
 185                if (is_bool($arg)) {
 186                    $trc .= $arg ? 'true' : 'false';
 187                } else
 188                if (is_numeric($arg))
 189                    $trc .= $arg;
 190                else
 191                if (is_string($arg)) {
 192                    $arg = preg_replace('/([\\s]+)/si', ' ', $arg);
 193                    if (strlen($arg) > _FF_TRACE_NAMELIMIT)
 194                        $arg = substr($arg, 0, _FF_TRACE_NAMELIMIT - 3) . '...';
 195                    $trc .= "'$arg'";
 196                } else
 197                if (is_array($arg))
 198                    $trc .= BFText::_('COM_BREEZINGFORMS_PROCESS_ARRAY');
 199                else
 200                if (is_object($arg))
 201                    $trc .= BFText::_('COM_BREEZINGFORMS_PROCESS_OBJECT');
 202                else
 203                if (is_resource($arg))
 204                    $trc .= BFText::_('COM_BREEZINGFORMS_PROCESS_RESOURCE');
 205                else
 206                    $trc .= _FACILEFORMS_PROCESS_UNKTYPE;
 207            } // foreach
 208        } // if
 209        $trc .= ") " . BFText::_('COM_BREEZINGFORMS_PROCESS_ATLINE') . " $line\n";
 210        $ff_processor->traceBuffer .= htmlspecialchars($trc, ENT_QUOTES);
 211        if ($ff_processor->traceMode & _FF_TRACEMODE_DIRECT)
 212            $ff_processor->dumpTrace();
 213    } // if
 214    array_push($ff_processor->traceStack, array($oldmode, 'f', $name, $line, $type, $id, $pane));
 215}
 216
 217// _ff_traceFunction
 218
 219function _ff_traceExit($line, $retval=null) {
 220    global $ff_processor;
 221
 222    if ($ff_processor->dying || ($ff_processor->traceMode & _FF_TRACEMODE_DISABLE))
 223        return;
 224    $info = array_pop($ff_processor->traceStack);
 225    if ($info) {
 226        $oldmode = $ff_processor->traceMode;
 227        $newmode = $info[0];
 228        $kind = $info[1];
 229        $name = $info[2];
 230        $type = $info[4];
 231        $id = $info[5];
 232        $pane = $info[6];
 233        if (_FF_DEBUG & _FF_DEBUG_EXIT) {
 234            $ff_processor->traceBuffer .=
 235                    htmlspecialchars(
 236                    "\n_FF_DEBUG_EXIT:" .
 237                    "\n  Info     = $kind $name at line $line" .
 238                    "\n  Old mode = " . $ff_processor->dispTraceMode($oldmode) .
 239                    "\n  New mode = " . $ff_processor->dispTraceMode($newmode) .
 240                    "\n", ENT_QUOTES
 241            );
 242            if ($ff_processor->traceMode & _FF_TRACEMODE_DIRECT)
 243                $ff_processor->dumpTrace();
 244        } // if
 245        if ($kind == 'p')
 246            $visible = $oldmode & _FF_TRACEMODE_PIECE;
 247        else
 248            $visible = $oldmode & _FF_TRACEMODE_FUNCTION;
 249        if ($visible) {
 250            $level = count($ff_processor->traceStack);
 251            for ($l = 0; $l < $level; $l++)
 252                $ff_processor->traceBuffer .= '  ';
 253            $ff_processor->traceBuffer .=
 254                    htmlspecialchars(
 255                    "-" . BFText::_('COM_BREEZINGFORMS_PROCESS_LEAVE') . " $name " . BFText::_('COM_BREEZINGFORMS_PROCESS_ATLINE') . " $line\n", ENT_QUOTES
 256            );
 257            if ($oldmode & _FF_TRACEMODE_DIRECT)
 258                $ff_processor->dumpTrace();
 259        } // if
 260        if ($oldmode != $newmode)
 261            $ff_processor->traceMode =
 262                    ($oldmode & ~_FF_TRACEMODE_VARIABLE) | ($newmode & _FF_TRACEMODE_VARIABLE);
 263    } else {
 264        $ff_processor->traceBuffer .= htmlspecialchars(BFText::_('COM_BREEZINGFORMS_PROCESS_WARNSTK') . "\n", ENT_QUOTES);
 265        if ($ff_processor->traceMode & _FF_TRACEMODE_DIRECT)
 266            $ff_processor->dumpTrace();
 267        $type = $id = $pane = null;
 268        $name = BFText::_('COM_BREEZINGFORMS_PROCESS_UNKNOWN');
 269    } // if
 270    return $retval;
 271}
 272
 273// _ff_traceExit
 274
 275function _ff_errorHandler($errno, $errstr, $errfile, $errline) {
 276    global $ff_processor, $ff_mossite, $database;
 277    $database = JFactory::getDBO();
 278
 279    if (isset($ff_processor->dying) && $ff_processor->dying)
 280        return;
 281
 282    $msg = "\n<strong>*** " . htmlspecialchars(BFText::_('COM_BREEZINGFORMS_PROCESS_EXCAUGHT'), ENT_QUOTES) . " ***</strong>\n" .
 283            htmlspecialchars(BFText::_('COM_BREEZINGFORMS_PROCESS_PHPLEVEL') . ' ', ENT_QUOTES);
 284    $fail = false;
 285    if (!defined('E_DEPRECATED')) {
 286        define('E_DEPRECATED', 8192);
 287    }
 288    switch ($errno) {
 289        case E_WARNING : $msg .= "E_WARNING";
 290            break;
 291        case E_NOTICE : $msg .= "E_NOTICE";
 292            break;
 293        case E_USER_ERROR : $msg .= "E_USER_ERROR";
 294            $fail = true;
 295            break;
 296        case E_USER_WARNING: $msg .= "E_USER_WARNING";
 297            break;
 298        case E_USER_NOTICE : $msg .= "E_USER_NOTICE";
 299            break;
 300        case E_DEPRECATED : $msg .= "E_DEPRECATED";
 301            break;
 302        case 2048 :
 303            if (_FF_IGNORE_STRICT)
 304                return;
 305            $msg .= "E_STRICT";
 306            break;
 307        default : $msg .= $errno;
 308            $fail = true;
 309    } // switch
 310    $msg .= htmlspecialchars(
 311            "\n" . BFText::_('COM_BREEZINGFORMS_PROCESS_PHPFILE') . " $errfile\n" .
 312            BFText::_('COM_BREEZINGFORMS_PROCESS_PHPLINE') . " $errline\n", ENT_QUOTES
 313    );
 314
 315    $n = 0;
 316    if (isset($ff_processor)) {
 317        $n = count($ff_processor->traceStack);
 318    }
 319
 320    if ($n) {
 321        $info = $ff_processor->traceStack[$n - 1];
 322        $name = htmlspecialchars($info[2] . ' ' . BFText::_('COM_BREEZINGFORMS_PROCESS_ATLINE') . ' ' . $info[3], ENT_QUOTES);
 323        $type = $info[4];
 324        $id = $info[5];
 325        $pane = $info[6];
 326        if ($type && $id && $ff_processor->runmode != _FF_RUNMODE_FRONTEND) {
 327            $url = $ff_mossite . '/administrator/index.php?option=com_breezingforms&format=html&tmpl=component';
 328            $what = $id;
 329            switch ($type) {
 330                case 'f':
 331                    $url .=
 332                            '&act=editpage' .
 333                            '&task=editform' .
 334                            '&form=' . $ff_processor->form;
 335                    if ($ff_processor->formrow->package != '')
 336                        $url .= '&pkg=' . urlencode($ff_processor->formrow->package);
 337                    if ($pane > 0)
 338                        $url .= '&tabpane=' . $pane;
 339                    $what = 'form ' . $ff_processor->formrow->name;
 340                    break;
 341                case 'e':
 342                    $page = 1;
 343                    foreach ($ff_processor->rows as $row)
 344                        if ($row->id == $id) {
 345                            $page = $row->page;
 346                            $what = $row->name;
 347                            break;
 348                        } // if
 349                    $what = 'element ' . $what;
 350                    $url .=
 351                            '&act=editpage' .
 352                            '&task=edit' .
 353                            '&form=' . $ff_processor->form .
 354                            '&page=' . $page .
 355                            '&ids[]=' . $id;
 356                    if ($ff_processor->formrow->package != '')
 357                        $url .= '&pkg=' . urlencode($ff_processor->formrow->package);
 358                    if ($pane > 0)
 359                        $url .= '&tabpane=' . $pane;
 360                    break;
 361                case 'p':
 362                    $package = '';
 363                    $database->setQuery("select name, package from #__facileforms_pieces where id=$id");
 364                    $rows = $database->loadObjectList();
 365                    if (count($rows)) {
 366                        $package = $rows[0]->package;
 367                        $what = $rows[0]->name;
 368                    }
 369                    $what = 'piece ' . $what;
 370                    $url .=
 371                            '&act=managepieces' .
 372                            '&task=edit' .
 373                            '&ids[]=' . $id;
 374                    if ($package != '')
 375                        $url .= '&pkg=' . urlencode($package);
 376                    break;
 377                case 's':
 378                    $package = '';
 379                    $database->setQuery("select name, package from #__facileforms_scripts where id=$id");
 380                    $rows = $database->loadObjectList();
 381                    if (count($rows)) {
 382                        $package = $rows[0]->package;
 383                        $what = $rows[0]->name;
 384                    }
 385                    $what = 'script ' . $what;
 386                    $url .=
 387                            '&act=managescripts' .
 388                            '&task=edit' .
 389                            '&ids[]=' . $id;
 390                    if ($package != '')
 391                        $url .= '&pkg=' . urlencode($package);
 392                    break;
 393                default:
 394                    $url = null;
 395            } // switch
 396            if ($url)
 397                $name = '<a href="#" ' .
 398                        'onMouseOver="window.status=\'Open ' . $what . '\';return true;" ' .
 399                        'onMouseOut="window.status=\'\';return true;" ' .
 400                        'onClick="ff_redirectParent(\'' . htmlspecialchars($url, ENT_QUOTES) . '\');return true;"' .
 401                        '>' . $name . '</a>';
 402        } // if
 403        $msg .= htmlspecialchars(BFText::_('COM_BREEZINGFORMS_PROCESS_LASTPOS'), ENT_QUOTES) . ' ' . $name . "\n";
 404    } // if
 405    $msg .= htmlspecialchars(BFText::_('COM_BREEZINGFORMS_PROCESS_ERRMSG') . " $errstr\n\n", ENT_QUOTES);
 406    if ($fail) {
 407        if (isset($ff_processor)) {
 408            $ff_processor->traceBuffer .= $msg;
 409            $ff_processor->suicide();
 410        }
 411    } else
 412    if (isset($ff_processor)) {
 413        if (($ff_processor->traceMode & _FF_TRACEMODE_DISABLE) == 0) {
 414            $ff_processor->traceBuffer .= $msg;
 415            if ($ff_processor->traceMode & _FF_TRACEMODE_DIRECT)
 416                $ff_processor->dumpTrace();
 417        }
 418    } // if
 419}
 420
 421// _ff_errorHandler
 422
 423class HTML_facileFormsProcessor {
 424
 425    var $okrun = null;     // running is allowed
 426    var $ip = null;     // visitor ip
 427    var $agent = null;     // visitor agent
 428    var $browser = null;     // visitors browser
 429    var $opsys = null;     // visitors operating system
 430    var $provider = null;     // visitors provider
 431    var $submitted = null;     // submit date/time
 432    var $formrow = null;     // form row
 433    var $form = null;     // form #
 434    var $form_id = null;     // html form id
 435    var $page = null;     // page id
 436    var $target = null;     // target form name
 437    var $rows = null;     // element rows
 438    var $rowcount = null;     // # of element rows
 439    var $runmode = null;     // current run mode _FF_RUNMODE_...
 440    var $inline = null;     // inline preview
 441    var $inframe = null;     // running in a frame
 442    var $template = null;     // 0-frontend 1-backend
 443    var $homepage = null;     // home page
 444    var $mospath = null;     // mos absolute path
 445    var $images = null;     // ff_images path
 446    var $uploads = null;     // ff_uploads path
 447    var $border = null;     // show border
 448    var $align = null;     // form alignment
 449    var $top = null;     // top margin
 450    var $suffix = null;     // class name suffix
 451    var $status = null;     // submit return status
 452    var $message = null;     // submit return message
 453    var $record_id = null;     // id of saved record
 454    var $submitdata = null;     // submitted data
 455    var $savedata = null;     // data for db save
 456    var $maildata = null;     // data for mail notification
 457    var $sfdata = null;
 458    var $xmldata = null;     // data for xml attachment
 459    var $mb_xmldata = null;     // data for mailback attachments
 460    var $queryCols = null;     // query column definitions
 461    var $queryRows = null;     // query rows
 462    var $showgrid = null;     // show grid in preview
 463    var $findtags = null;     // tags to be replaced
 464    var $replacetags = null;     // tag replacements
 465    var $dying = null;     // form is dying
 466    var $errrep = null;     // remember old error reporting
 467    var $traceMode = null;     // trace mode
 468    var $traceStack = null;     // trace stack
 469    var $traceBuffer = null;     // trace buffer
 470    var $user_id = null;
 471    var $username = null;
 472    var $user_full_name = null;
 473    var $mailbackRecipients = array();
 474    var $editable = null;
 475    var $editable_override = null;
 476    var $sendNotificationAfterPayment = false;
 477    public $draggableDivIds = array();
 478    public $isMobile = false;
 479    public $quickmode = null;
 480    
 481    function HTML_facileFormsProcessor(
 482    $runmode, // _FF_RUNMODE_FRONTEND, ..._BACKEND, ..._PREVIEW
 483            $inframe, // run in iframe
 484            $form, // form id
 485            $page = 1, // page #
 486            $border = 0, // show border
 487            $align = 1, // align code
 488            $top = 0, // top margin
 489            $target = '', // target form name
 490            $suffix = '', // class name suffix
 491            $editable = 0, $editable_override = 0) {
 492        global $database, $ff_config, $ff_mossite, $ff_mospath, $ff_processor;
 493        $ff_processor = $this;
 494        $database = JFactory::getDBO();
 495        $this->dying = false;
 496        $this->runmode = $runmode;
 497        $this->inframe = $inframe;
 498        $this->form = $form;
 499        $this->page = $page;
 500        $this->border = $border;
 501        $this->align = $align;
 502        $this->top = $top;
 503        $this->target = $target;
 504        $this->suffix = trim($suffix);
 505        $this->editable = $editable;
 506        $this->editable_override = $editable_override;
 507
 508        if (!class_exists('JBrowser')) {
 509            require_once(JPATH_SITE . '/libraries/joomla/environment/browser.php');
 510        }
 511
 512        $this->ip = $_SERVER['REMOTE_ADDR'];
 513        $this->agent = JBrowser::getInstance()->getAgentString();
 514
 515        $this->browser = JBrowser::getInstance()->getAgentString();
 516
 517        $jbrowserInstance = JBrowser::getInstance();
 518        $this->opsys = $jbrowserInstance->getPlatform();
 519
 520        if ($ff_config->getprovider == 0)
 521            $this->provider = BFText::_('COM_BREEZINGFORMS_PROCESS_UNKNOWN');
 522        else {
 523            $host = @GetHostByAddr($this->ip);
 524            $this->provider = preg_replace('/^./', '', strchr($host, '.'));
 525        } // if
 526
 527        $this->submitted = date('Y-m-d H:i:s');
 528
 529        /*
 530          $format = JText::_('DATE_FORMAT_LC2');
 531          if ( !$format ) {
 532          $this->submitted = date('Y-m-d H:i:s');
 533          }else{
 534          $config = JFactory::getConfig();
 535          $offset = $config->getValue('config.offset');
 536          $instance = JFactory::getDate(date('Y-m-d H:i:s'));
 537          $instance->setOffset($offset);
 538          $this->submitted = $instance->toFormat($format);
 539          } */
 540
 541        $this->formrow = new facileFormsForms($database);
 542        $this->formrow->load($form);
 543        if ($this->formrow->published) {
 544            $database->setQuery(
 545                    "select * from #__facileforms_elements " .
 546                    "where form=" . $this->form . " and published=1 " .
 547                    "order by page, ordering"
 548            );
 549            $this->rows = $database->loadObjectList();
 550            $this->rowcount = count($this->rows);
 551        } // if
 552        $this->inline = 0;
 553        $this->template = 0;
 554        $this->form_id = "ff_form" . $form;
 555        if ($runmode == _FF_RUNMODE_FRONTEND) {
 556            $this->homepage = $ff_mossite;
 557        } else {
 558            if ($this->inframe) {
 559                $this->homepage = $ff_mossite . '/administrator/index.php?tmpl=component';
 560                if ($this->formrow->runmode == 2)
 561                    $this->template++;
 562            } else {
 563                $this->template++;
 564                if ($runmode == _FF_RUNMODE_PREVIEW) {
 565                    $this->inline = 1;
 566                    $this->form_id = "adminForm";
 567                } // if
 568                $this->homepage = 'index.php?tmpl=component';
 569            } // if
 570        } // if
 571        $this->mospath = $ff_mospath;
 572        $this->mossite = $ff_mossite;
 573        $this->findtags =
 574                array(
 575                    '{ff_currentpage}',
 576                    '{ff_lastpage}',
 577                    '{ff_name}',
 578                    '{ff_title}',
 579                    '{ff_homepage}',
 580                    '{mospath}',
 581                    '{mossite}'
 582        );
 583        $this->replacetags =
 584                array(
 585                    $this->page,
 586                    $this->formrow->pages,
 587                    $this->formrow->name,
 588                    $this->formrow->title,
 589                    $this->homepage,
 590                    $this->mospath,
 591                    $this->mossite
 592        );
 593        $this->images = str_replace($this->findtags, $this->replacetags, $ff_config->images);
 594        $this->findtags[] = '{ff_images}';
 595        $this->replacetags[] = $this->images;
 596        $this->uploads = str_replace($this->findtags, $this->replacetags, $ff_config->uploads);
 597        $this->findtags[] = '{ff_uploads}';
 598        $this->replacetags[] = $this->uploads;
 599        // CONTENTBUILDER
 600        $this->findtags[] = '{CBSite}';
 601        $this->replacetags[] = JPATH_SITE;
 602        $this->findtags[] = '{cbsite}';
 603        $this->replacetags[] = JPATH_SITE;
 604        $this->showgrid =
 605                $runmode == _FF_RUNMODE_PREVIEW
 606                && $this->formrow->prevmode > 0
 607                && $ff_config->gridshow == 1
 608                && $ff_config->gridsize > 1;
 609        $this->okrun = $this->formrow->published;
 610
 611        if ($this->okrun)
 612            switch ($this->runmode) {
 613                case _FF_RUNMODE_FRONTEND:
 614                    $this->okrun = ($this->formrow->runmode == 0 || $this->formrow->runmode == 1);
 615                    break;
 616                case _FF_RUNMODE_BACKEND:
 617                    $this->okrun = ($this->formrow->runmode == 0 || $this->formrow->runmode == 2);
 618                    break;
 619                default:;
 620            } // switch
 621        $this->traceMode = _FF_TRACEMODE_FIRST;
 622        $this->traceStack = array();
 623        $this->traceBuffer = null;
 624    }
 625
 626//  HTML_facileFormsProcessor
 627
 628    function dispTraceMode($mode) {
 629        if (!is_int($mode))
 630            return $mode;
 631        $m = '(';
 632        if ($mode & _FF_TRACEMODE_FIRST)
 633            $m .= 'first ';
 634        $m .= ( $mode & _FF_TRACEMODE_DIRECT ? 'direct' : $mode & _FF_TRACEMODE_APPEND ? 'append' : 'popup');
 635        if ($mode & _FF_TRACEMODE_DISABLE)
 636            $m .= ' disable';
 637        else {
 638            switch ($mode & _FF_TRACEMODE_PRIORITY) {
 639                case 0: $m .= ' minimum';
 640                    break;
 641                case 1: $m .= ' low';
 642                    break;
 643                case 2: $m .= ' normal';
 644                    break;
 645                case 3: $m .= ' high';
 646                    break;
 647                default: $m .= ' maximum';
 648                    break;
 649            } // switch
 650            $m .= $mode & _FF_TRACEMODE_LOCAL ? ' local' : ' global';
 651            switch ($mode & _FF_TRACEMODE_TOPIC) {
 652                case 0 : $m .= ' none';
 653                    break;
 654                case _FF_TRACEMODE_TOPIC: $m .= ' all';
 655                    break;
 656                default:
 657                    if ($mode & _FF_TRACEMODE_EVAL)
 658                        $m .= ' eval';
 659                    if ($mode & _FF_TRACEMODE_PIECE)
 660                        $m .= ' piece';
 661                    if ($mode & _FF_TRACEMODE_FUNCTION)
 662                        $m .= ' function';
 663                    if ($mode & _FF_TRACEMODE_MESSAGE)
 664                        $m .= ' message';
 665            } // switch
 666        } // if
 667        return $m . ')';
 668    }
 669
 670// dispTraceMode
 671
 672    function trim(&$code) {
 673        $len = strlen($code);
 674        if (!$len)
 675            return false;
 676        if (strpos(" \t\r\n", $code{0}) === false && strpos(" \t\r\n", $code{$len - 1}) === false)
 677            return true;
 678        $code = trim($code);
 679        return $code != '';
 680    }
 681
 682// trim
 683
 684    function nonblank(&$code) {
 685        return preg_match("/[^\\s]+/si", $code);
 686    }
 687
 688// nonblank
 689
 690    function getClassName($classdef) {
 691        $name = '';
 692        if (strpos($classdef, ';') === false)
 693            $name = $classdef;
 694        else {
 695            $defs = explode(';', $classdef);
 696            $name = $defs[$this->template];
 697        } // if
 698        if ($this->trim($name))
 699            $name .= $this->suffix;
 700        return $name;
 701    }
 702
 703// getClassName
 704
 705    function expJsValue($mixed, $indent='') {
 706        if (is_null($mixed))
 707            return $indent . 'null';
 708
 709        if (is_bool($mixed))
 710            return $mixed ? $indent . 'true' : $indent . 'false';
 711
 712        if (is_numeric($mixed))
 713            return $indent . $mixed;
 714
 715        if (is_string($mixed))
 716            return
 717            $indent . "'" .
 718            str_replace(
 719                    array("\\", "'", "\r", "<", "\n"), array("\\\\", "\\'", "\\r", "\\074", "\\n'+" . nl() . $indent . "'"), $mixed
 720            ) .
 721            "'";
 722
 723        if (is_array($mixed)) {
 724            $dst = $indent . '[' . nl();
 725            $next = false;
 726            foreach ($mixed as $value) {
 727                if ($next)
 728                    $dst .= "," . nl(); else
 729                    $next = true;
 730                $dst .= $this->expJsValue($value, $indent . "\t");
 731            } // foreach
 732            return $dst . nl() . $indent . ']';
 733        } // if
 734
 735        if (is_object($mixed)) {
 736            $dst = $indent . '{' . nl();
 737            $arr = get_object_vars($mixed);
 738            $next = false;
 739            foreach ($arr as $key => $value) {
 740                if ($next)
 741                    $dst .= "," . nl(); else
 742                    $next = true;
 743                $dst .= $indent . $key . ":" . nl() . $this->expJsValue($value, $indent . "\t");
 744            } // foreach
 745            return $dst . nl() . $indent . '}';
 746        } // if
 747        // not supported types
 748        if (is_resource($mixed))
 749            return $indent . "'" . BFText::_('COM_BREEZINGFORMS_PROCESS_RESOURCE') . "'";
 750
 751        return $indent . "'" . BFText::_('COM_BREEZINGFORMS_PROCESS_UNKNOWN') . "'";
 752    }
 753
 754// expJsValue
 755
 756    function expJsVar($name, $mixed) {
 757        return $name . ' = ' . $this->expJsValue($mixed) . ';' . nl();
 758    }
 759
 760// expJsVar
 761
 762    function dumpTrace() {
 763        if ($this->traceMode & _FF_TRACEMODE_DIRECT) {
 764            $html = ob_get_contents();
 765            ob_end_clean();
 766            echo htmlspecialchars($html, ENT_QUOTES) . $this->traceBuffer;
 767            ob_start();
 768            $this->traceBuffer = null;
 769            return;
 770        } // if
 771        if (!$this->traceBuffer)
 772            return;
 773        if ($this->traceMode & _FF_TRACEMODE_APPEND) {
 774            echo '<pre>' . $this->traceBuffer . '</pre>';
 775            $this->traceBuffer = null;
 776            return;
 777        } // if
 778        echo
 779        '<script type="text/javascript">' . nl() .
 780        '<!--' . nl() .
 781        $this->expJsVar('if(typeof ff_processor != "undefined")ff_processor.traceBuffer', $this->traceBuffer);
 782        if ($this->dying)
 783            echo 'onload = ff_traceWindow();' . nl();
 784        echo
 785        '-->' . nl() .
 786        '</script>' . nl();
 787        $this->traceBuffer = null;
 788    }
 789
 790// dumpTrace
 791
 792    function traceEval($name) {
 793        if (($this->traceMode & _FF_TRACEMODE_DISABLE) ||
 794                !($this->traceMode & _FF_TRACEMODE_EVAL) ||
 795                $this->dying)
 796            return;
 797        $level = count($this->traceStack);
 798        for ($l = 0; $l < $level; $l++)
 799            $this->traceBuffer .= '  ';
 800        $this->traceBuffer .= htmlspecialchars("eval($name)\n", ENT_QUOTES);
 801        if ($this->traceMode & _FF_TRACEMODE_DIRECT)
 802            $this->dumpTrace();
 803    }
 804
 805// traceEval
 806
 807    function suicide() {
 808        if ($this->dying)
 809            return false;
 810        $this->dying = true;
 811        $this->errrep = error_reporting(0);
 812        return true;
 813    }
 814
 815// suicide
 816
 817    function bury() {
 818        if (!$this->dying)
 819            return false;
 820        if ($this->traceMode & _FF_TRACEMODE_DIRECT)
 821            $this->dumpTrace();
 822        ob_end_clean();
 823        if ($this->traceMode & _FF_TRACEMODE_DIRECT)
 824            echo '</pre>'; else
 825            $this->dumpTrace();
 826        error_reporting($this->errrep);
 827        restore_error_handler();
 828        return true;
 829    }
 830
 831// bury
 832
 833    function findToken(&$code, &$spos, &$offs) {
 834        $srch = '#(function|return|_ff_trace|ff_trace[ \\t]*\\(|//|/\*|\*/|\\\\"|\\\\\'|{|}|\(|\)|;|"|\'|\n)#si';
 835        $match = array();
 836        if (!preg_match($srch, $code, $match, PREG_OFFSET_CAPTURE, $spos))
 837            return '';
 838        $token = strtolower($match[0][0]);
 839        $offs = $match[0][1];
 840        $spos = $offs + strlen($token);
 841        return $token;
 842    }
 843
 844// findToken
 845
 846    function findRealToken(&$code, &$spos, &$offs, &$line) {
 847        $linecmt = $blockcmt = false;
 848        $quote = null;
 849        for (;;) {
 850            $token = preg_replace('/[ \\t]*/', '', $this->findToken($code, $spos, $offs));
 851            switch ($token) {
 852                case '':
 853                    return '';
 854                case 'function':
 855                case 'return';
 856                case 'ff_trace(';
 857                case '{':
 858                case '}':
 859                case '(':
 860                case ')':
 861                case ';':
 862                    if (!$linecmt && !$blockcmt && !$quote)
 863                        return $token;
 864                    break;
 865                case "\n":
 866                    $line++;
 867                    $linecmt = false;
 868                    break;
 869                case '//':
 870                    if (!$blockcmt && !$quote)
 871                        $linecmt = true;
 872                    break;
 873                case '/*':
 874                    if (!$linecmt && !$quote)
 875                        $longcmt = true;
 876                    break;
 877                case '"':
 878                case "'":
 879                    if ($quote == $token)
 880                        $quote = null;
 881                    else
 882                    if (!$linecmt && !$blockcmt && !$quote)
 883                        $quote = $token;
 884                    break;
 885                default:
 886                    break;
 887            } // switch
 888        } // for
 889    }
 890
 891// findRealToken
 892
 893    function patchCode($mode, $code, $name, $type, $id, $pane) {
 894        $flevel = $cpos = $spos = $offs = 0;
 895        $bye = false;
 896        $fstack = array();
 897        $line = 1;
 898        if ($type && $id) {
 899            $type = "'$type'";
 900            if (!$pane)
 901                $pane = 'null';
 902        } else
 903            $type = $id = $pane = 'null';
 904        $name = str_replace("'", "\\'", $name);
 905        $dst = "_ff_tracePiece($mode,'$name',$line,$type,$id,$pane);";
 906        while (!$bye) {
 907            switch ($this->findRealToken($code, $spos, $offs, $line)) {
 908                case '': $bye = true;
 909                    break;
 910                case 'function':
 911                    $brk = false;
 912                    while (!$brk) {
 913                        // consume tokens until finding the opening bracket
 914                        switch ($this->findRealToken($code, $spos, $offs, $line)) {
 915                            case '': $bye = $brk = true;
 916                                break;
 917                            case '{':
 918                                $dst .=
 919                                        substr($code, $cpos, $spos - $cpos) .
 920                                        '$_ff_traceArgs = func_get_args();' .
 921                                        '_ff_traceFunction(' . $mode . ',__FUNCTION__,' . $line . ',' . $type . ',' . $id . ',' . $pane . ',$_ff_traceArgs);' .
 922                                        '$_ff_traceArgs=null;';
 923                                $cpos = $spos;
 924                                if ($flevel)
 925                                    array_push($fstack, $flevel);
 926                                $flevel = 1;
 927                                $brk = true;
 928                                break;
 929                            default:;
 930                        } // switch
 931                    } // while
 932                    break;
 933                case 'return':
 934                    $dst .= substr($code, $cpos, $spos - $cpos);
 935                    $cpos = $spos;
 936                    $brk = false;
 937                    while (!$brk) {
 938                        // consume tokens until semicolon found
 939                        switch ($this->findRealToken($code, $spos, $offs, $line)) {
 940                            case '': $bye = $brk = true;
 941                                break;
 942                            case ';':
 943                                $arg = substr($code, $cpos, $offs - $cpos);
 944                                if ($this->nonblank($arg))
 945                                    $dst .= ' _ff_traceExit(' . $line . ',' . $arg . ');';
 946                                else
 947                                    $dst .= ' _ff_traceExit(' . $line . ');';
 948                                $cpos = $spos;
 949                                $brk = true;
 950                                break;
 951                            default:;
 952                        } // switch
 953                    } // while
 954                    break;
 955                case 'ff_trace(':
 956                    $dst .= substr($code, $cpos, $offs - $cpos);
 957                    $cpos = $spos;
 958                    $brk = false;
 959                    $lvl = 0;
 960                    while (!$brk) {
 961                        // consume tokens until finding the closing bracket
 962                        switch ($this->findRealToken($code, $spos, $offs, $line)) {
 963                            case '': $bye = $brk = true;
 964                                break;
 965                            case '(': $lvl++;
 966                                break;
 967                            case ')':
 968                                if ($lvl)
 969                                    $lvl--; else
 970                                    $brk = true;
 971                                break;
 972                            default:;
 973                        } // switch
 974                    } // while
 975                    $par = $offs == $cpos ? '' : substr($code, $cpos, $offs - $cpos);
 976                    $dst .= " _ff_trace($line";
 977                    if ($this->nonblank($par))
 978                        $dst .= ',';
 979                    break;
 980                case '{':
 981                    if ($flevel > 0)
 982                        $flevel++;
 983                    break;
 984                case '}';
 985                    if ($flevel > 0) {
 986                        $flevel--;
 987                        if (!$flevel) {
 988                            $dst .= substr($code, $cpos, $offs - $cpos) . ' _ff_traceExit(' . $line . ');}';
 989                            $cpos = $spos;
 990                            if (count($fstack))
 991                                $flevel = array_pop($fstack);
 992                        } // if
 993                    } // if
 994                    break;
 995                default:
 996            } // switch
 997        } // while
 998        $spos = strlen($code);
 999        if ($cpos < $spos)
1000            $dst .= substr($code, $cpos, $spos - $cpos);
1001        $line--;
1002        $dst .= "_ff_traceExit($line);";
1003        if (_FF_DEBUG & _FF_DEBUG_PATCHEDCODE) {
1004            $this->traceBuffer .=
1005                    htmlspecialchars(
1006                    "\n_FF_DEBUG_PATCHEDCODE:" .
1007                    "\n  Mode = " . $this->dispTraceMode($mode) .
1008                    "\n  Name = $name" .
1009                    "\n  Link = $type $id $pane" .
1010                    "\n------ begin patched code ------" .
1011                    "\n$dst" .
1012                    "\n------- end patched code -------" .
1013                    "\n", ENT_QUOTES
1014            );
1015            if ($this->traceMode & _FF_TRACEMODE_DIRECT)
1016                $this->dumpTrace();
1017        } // if
1018        return $dst;
1019    }
1020
1021// patchCode
1022
1023    function prepareEvalCode(&$code, $name, $type, $id, $pane) {
1024        if ($this->dying)
1025            return false;
1026        if (!$this->nonblank($code))
1027            return false;
1028        $code .= "\n/*'/*\"/**/;"; // closes all comments and strings that my be open
1029        $disable = ($this->traceMode & _FF_TRACEMODE_DISABLE) ? true : false;
1030        if (!$disable) {
1031            $mode = 'null';
1032            $srch =
1033                    '#' .
1034                    '^[\\s]*(//\+trace|/\*\+trace)' .
1035                    '[ \\t]*([\\w]+)?' .
1036                    '[ \\t]*([\\w]+)?' .
1037                    '[ \\t]*([\\w]+)?' .
1038                    '[ \\t]*([\\w]+)?' .
1039                    '[ \\t]*([\\w]+)?' .
1040                    '[ \\t]*([\\w]+)?' .
1041                    '[ \\t]*(\\*/|\\r\\n)?' .
1042                    '#';
1043            $match = array();
1044            if (preg_match($srch, $code, $match)) {
1045                $mode = 2;
1046                $append = $direct = $xeval = $piece = $func = $msg = false;
1047                $local = $def = true;
1048                for ($m = 2; $m < count($match); $m++)
1049                    switch ($match[$m]) {
1050                        // disable
1051                        case 'dis' :
1052                        case 'disable' : $disable = true;
1053                            break;
1054                        // mode
1055                        case 'pop' :
1056                        case 'popup' : $direct = $append = false;
1057                            break;
1058                        case 'app' :
1059                        case 'append' : $append = true;
1060                            $direct = false;
1061                            break;
1062                        case 'dir' :
1063                        case 'direct' : $direct = true;
1064                            $append = false;
1065                            break;
1066                        // priority
1067                        case 'min' :
1068                        case 'minimum' : $mode = 0;
1069                            break;
1070                        case 'low' : $mode = 1;
1071                            break;
1072                        case 'nor' :
1073                        case 'normal' : $mode = 2;
1074                            break;
1075                        case 'hig' :
1076                        case 'high' : $mode = 3;
1077                            break;
1078                        case 'max' :
1079                        case 'maximum' : $mode = 4;
1080                            break;
1081                        // scope
1082                        case 'glo' :
1083                        case 'global' : $local = false;
1084                            break;
1085                        case 'loc' :
1086                        case 'local' : $local = true;
1087                            break;
1088                        // topics
1089                        case 'all' : $def = false;
1090                            $xeval = $piece = $func = $msg = true;
1091                            break;
1092                        case 'non' :
1093                        case 'none' : $def = $xeval = $piece = $func = $msg = false;
1094                            break;
1095                        case 'eva' :
1096                        case 'eval' : $def = false;
1097                            $xeval = true;
1098                            break;
1099                        case 'pie' :
1100                        case 'piece' : $def = false;
1101                            $piece = true;
1102                            break;
1103                        case 'fun' :
1104                        case 'function': $def = false;
1105                            $func = true;
1106                            break;
1107                        case 'mes' :
1108                        case 'message' : $def = false;
1109                            $msg = true;
1110                            break;
1111                        default : break;
1112                    } // switch
1113
1114                if ($def) {
1115                    $xeval = false;
1116                    $piece = $func = $msg = true;
1117                }
1118                if ($xeval)
1119                    $mode |= _FF_TRACEMODE_EVAL;
1120                if ($piece)
1121                    $mode |= _FF_TRACEMODE_PIECE;
1122                if ($func)
1123                    $mode |= _FF_TRACEMODE_FUNCTION;
1124                if ($msg)
1125                    $mode |= _FF_TRACEMODE_MESSAGE;
1126                if ($local)
1127                    $mode |= _FF_TRACEMODE_LOCAL;
1128
1129                $first = ($this->traceMode & _FF_TRACEMODE_FIRST) ? true : false;
1130                if ($first) {
1131                    $oldMode = $this->traceMode;
1132                    $this->traceMode = 0;
1133                    if ($disable)
1134                        $this->traceMode |= _FF_TRACEMODE_DISABLE;
1135                    if ($append)
1136                        $this->traceMode |= _FF_TRACEMODE_APPEND;
1137                    if ($direct) {
1138                        $this->traceMode |= _FF_TRACEMODE_DIRECT;
1139                        $html = ob_get_contents();
1140                        ob_end_clean();
1141                        echo '<pre>' . htmlspecialchars($html, ENT_QUOTES);
1142                        ob_start();
1143                    } // if
1144                } else
1145                    $disable = false;
1146                if (_FF_DEBUG & _FF_DEBUG_DIRECTIVE) {
1147                    $_deb = "\n_FF_DEBUG_DIRECTIVE:";
1148                    if ($first)
1149                        $_deb .= "\n  Previous mode=" . $this->dispTraceMode($oldMode);
1150                    $_deb .=
1151                            "\n  Trace mode   =" . $this->dispTraceMode($this->traceMode) .
1152                            "\n  New mode     =" . $this->dispTraceMode($mode) .
1153                            "\n";
1154                    $this->traceBuffer .= htmlspecialchars($_deb, ENT_QUOTES);
1155                    if ($this->traceMode & _FF_TRACEMODE_DIRECT)
1156                        $this->dumpTrace();
1157                } // if
1158            } // if trace directive
1159            if (!$disable) {
1160                if (!$name) {
1161                    $name = preg_replace('/([\\s]+)/si', ' ', $code);
1162                    if (strlen($name) > _FF_TRACE_NAMELIMIT)
1163                        $name = substr($code, 0, _FF_TRACE_NAMELIMIT - 3) . '...';
1164                } // if
1165                $code = $this->patchCode($mode, $code, $name, $type, $id, $pane);
1166            } // if
1167        } // if trace not disabled
1168        $code = str_replace($this->findtags, $this->replacetags, $code);
1169        return true;
1170    }
1171
1172// prepareEvalCode
1173
1174    function getPieceById($id, $name=null) {
1175        if ($this->dying)
1176            return '';
1177        global $database;
1178        $database = JFactory::getDBO();
1179        $database->setQuery(
1180                'select code, name from #__facileforms_pieces ' .
1181                'where id=' . $id . ' and published=1 '
1182        );
1183        $rows = $database->loadObjectList();
1184        if ($rows && count($rows)) {
1185            $name = $rows[0]->name;
1186            return $rows[0]->code;
1187        } // if
1188        return '';
1189    }
1190
1191// getPieceById
1192
1193    function getPieceByName($name, $id=null) {
1194        if ($this->dying)
1195            return '';
1196        global $database;
1197        $database = JFactory::getDBO();
1198        $database->setQuery(
1199                'select id, code from #__facileforms_pieces ' .
1200                'where name=\'' . $name . '\' and published=1 ' .
1201                'order by id desc'
1202        );
1203        $rows = $database->loadObjectList();
1204        if ($rows && count($rows)) {
1205            $id = $rows[0]->id;
1206            return $rows[0]->code;
1207        } // if
1208        return '';
1209    }
1210
1211// getPieceByName
1212
1213    function execPiece($code, $name, $type, $id, $pane) {
1214        $ret = '';
1215        if ($this->prepareEvalCode($code, $name, $type, $id, $pane)) {
1216            $this->traceEval($name);
1217
1218            $ret = eval($code);
1219        } // if
1220        return $ret;
1221    }
1222
1223// execPiece
1224
1225    function execPieceById($id) {
1226        $name = null;
1227        $code = $this->getPieceById($id, $name);
1228        return $this->execPiece($code, BFText::_('COM_BREEZINGFORMS_PROCESS_PIECE') . " $name", 'p', $id, null);
1229    }
1230
1231// execPieceById
1232
1233    function execPieceByName($name) {
1234        $id = null;
1235        $code = $this->getPieceByName($name, $id);
1236        return $this->execPiece($code, BFText::_('COM_BREEZINGFORMS_PROCESS_PIECE') . " $name", 'p', $id, null);
1237    }
1238
1239// execPieceByName
1240
1241    function replaceCode($code, $name, $type, $id, $pane) {
1242        if ($this->dying)
1243            return '';
1244        $p1 = 0;
1245        $l = strlen($code);
1246        $c = '';
1247        $n = 0;
1248        while ($p1 < $l) {
1249            $p2 = strpos($code, '<?php', $p1);
1250            if ($p2 === false)
1251                $p2 = $l;
1252            $c .= substr($code, $p1, $p2 - $p1);
1253            $p1 = $p2;
1254            if ($p1 < $l) {
1255                $p1 += 5;
1256                $p2 = strpos($code, '?>', $p1);
1257                if ($p2 === false)
1258                    $p2 = $l;
1259                $n++;
1260                $c .= $this->execPiece(substr($code, $p1, $p2 - $p1), $name . "[$n]", $type, $id, $pane);
1261                if ($this->dying)
1262                    return '';
1263                $p1 = $p2 + 2;
1264            } // if
1265        } // while
1266        return str_replace($this->findtags, $this->replacetags, $c);
1267    }
1268
1269// replaceCode
1270
1271    function compileQueryCol(&$elem, &$coldef) {
1272        $coldef->comp = array();
1273        if ($this->trim(str_replace($this->findtags, $this->replacetags, $coldef->value))) {
1274            $c = $p1 = 0;
1275            $l = strlen($coldef->value);
1276            while ($p1 < $l) {
1277                $p2 = strpos($coldef->value, '<?php', $p1);
1278                if ($p2 === false)
1279                    $p2 = $l;
1280                $coldef->comp[$c] = array(
1281                    false,
1282                    str_replace(
1283                            $this->findtags, $this->replacetags, trim(substr($coldef->value, $p1, $p2 - $p1))
1284                    )
1285                );
1286                if ($this->trim($coldef->comp[$c][1]))
1287                    $c++;
1288                $p1 = $p2;
1289                if ($p1 < $l) {
1290                    $p1 += 5;
1291                    $p2 = strpos($coldef->value, '?>', $p1);
1292                    if ($p2 === false)
1293                        $p2 = $l;
1294                    $coldef->comp[$c] = array(true, substr($coldef->value, $p1, $p2 - $p1));
1295                    if ($this->prepareEvalCode(
1296                                    $coldef->comp[$c][1], BFText::_('COM_BREEZINGFORMS_PROCESS_QVALUEOF') . " " . $elem->name . "::" . $coldef->name, 'e', $elem->id, 2
1297                            )
1298                    )
1299                        $c++;
1300                    $p1 = $p2 + 2;
1301                } // if
1302            } // while
1303            if ($c > count($coldef->comp))
1304                array_pop($coldef->comp);
1305        } // if non-empty
1306    }
1307
1308// compileQueryCol
1309
1310    function execQueryValue($code, &$elem, &$row, &$coldef, $value) {
1311        $this->traceEval(BFText::_('COM_BREEZINGFORMS_PROCESS_QVALUEOF') . " " . $elem->name . "::" . $coldef->name);
1312        return eval($code);
1313    }
1314
1315// execQueryValue
1316
1317    function execQuery(&$elem, &$valrows, &$coldefs) {
1318        $ret = null;
1319        $code = $elem->data2;
1320        if ($this->prepareEvalCode($code, BFText::_('COM_BREEZINGFORMS_PROCESS_QPIECEOF') . " " . $elem->name, 'e', $elem->id, 1)) {
1321            $rows = array();
1322            $this->traceEval(BFText::_('COM_BREEZINGFORMS_PROCESS_QPIECEOF') . " " . $elem->name);
1323            eval($code);
1324            $rcnt = count($rows);
1325            $ccnt = count($coldefs);
1326            $valrows = array();
1327            for ($r = 0; $r < $rcnt; $r++) {
1328                $row = &$rows[$r];
1329                $valrow = array();
1330                for ($c = 0; $c < $ccnt; $c++) {
1331                    $coldef = &$coldefs[$c];
1332                    $cname = $coldef->name;
1333                    $value = isset($row->$cname) ? str_replace($this->findtags, $this->replacetags, $row->$cname) : '';
1334                    $xcnt = count($coldef->comp);
1335                    if (!$xcnt)
1336                        $valrow[] = $value;
1337                    else {
1338                        $val = '';
1339                        for ($x =

Large files files are truncated, but you can click here to view the full file