Beispiel #1
0
function camila_worktable_filter_decode($str, $wt_id)
{
    global $_CAMILA;
    $adoMetaColumns = $_CAMILA['db']->MetaColumns(camila_worktable_get_table_name($wt_id));
    $connOr = ' ' . camila_get_translation('camila.report.or') . ' ';
    $connAnd = ' ' . camila_get_translation('camila.report.and') . ' ';
    $connOrCount = substr_count($str, $connOr);
    $connAndCount = substr_count($str, $connAnd);
    $connCount = $connOrCount + $connAndCount;
    $offset = 0;
    $result = array();
    $condArray = camila_get_translation_array('camila.report.condstring');
    if ($connCount > 0) {
        for ($i = 0; $i < $connCount; $i++) {
            $pos1 = stripos($str, $connOr, $offset);
            $pos2 = stripos($str, $connAnd, $offset);
            $pos1 = $pos1 > 0 ? $pos1 : 999;
            $pos2 = $pos2 > 0 ? $pos2 : 999;
            $pos = min($pos1, $pos2);
            $criteria = substr($str, $offset, $pos) . ' ';
            $field = substr($criteria, 1, stripos($criteria, "\"", 1) - 1);
            $cond = substr($criteria, strlen($field) + 3, stripos(substr($criteria, strlen($field) + 3), "\"") - 1);
            $value = substr($criteria, strlen($field) + strlen($cond) + 5, -2);
            $offset = $offset + $pos + ($pos1 == $pos ? strlen($connOr) : strlen($connAnd));
            $colInfo = camila_worktable_get_col_name($wt_id, $field);
            $result['camila_w' . ($i + 1) . 'f'] = '_' . camila_worktable_get_schema_type($colInfo['type']) . '_' . $colInfo['col_name'];
            $result['camila_w' . ($i + 1) . 'c'] = array_search($cond, $condArray);
            $result['camila_w' . ($i + 1) . 'v'] = $value;
            $result['camila_w' . ($i + 2) . 'w'] = $pos1 == $pos ? 'or' : 'and';
        }
        $criteria = substr($str, $offset, $pos) . ' ';
        $field = substr($criteria, 1, stripos($criteria, "\"", 1) - 1);
        $cond = substr($criteria, strlen($field) + 3, stripos(substr($criteria, strlen($field) + 3), "\"") - 1);
        $value = substr($criteria, strlen($field) + strlen($cond) + 5, -2);
        $colInfo = camila_worktable_get_col_name($wt_id, $field);
        $result['camila_w' . ($i + 1) . 'f'] = '_' . $_CAMILA['db']->MetaType($adoMetaColumns[strtoupper($colInfo['col_name'])]->type) . '_' . $colInfo['col_name'];
        $result['camila_w' . ($i + 1) . 'c'] = array_search($cond, $condArray);
        $result['camila_w' . ($i + 1) . 'v'] = $value;
    } else {
        $criteria = $str . ' ';
        $field = substr($criteria, 1, stripos($criteria, "\"", 1) - 1);
        $cond = substr($criteria, strlen($field) + 3, stripos(substr($criteria, strlen($field) + 3), "\"") - 1);
        $value = substr($criteria, strlen($field) + strlen($cond) + 5, -2);
        $colInfo = camila_worktable_get_col_name($wt_id, $field);
        $result['camila_w1f'] = '_' . $_CAMILA['db']->MetaType($adoMetaColumns[strtoupper($colInfo['col_name'])]->type) . '_' . $colInfo['col_name'];
        $result['camila_w1v'] = $value;
        $result['camila_w1c'] = array_search($cond, $condArray);
    }
    return $result;
}
 function xls_import($id, $returl = '')
 {
     global $_CAMILA;
     require_once CAMILA_DIR . 'datagrid/form.class.php';
     require_once CAMILA_DIR . 'datagrid/elements/form/hidden.php';
     require_once CAMILA_DIR . 'datagrid/elements/form/filebox.php';
     require_once CAMILA_DIR . 'datagrid/elements/form/static_listbox.php';
     //if ($returl != '')
     //    $form3 = new phpform('camilastep4', $returl);
     //else
     $form3 = new phpform('camilastep4', 'cf_worktable_wizard_step4.php');
     $form3->submitbutton = camila_get_translation('camila.wizard.next');
     $form3->drawrules = false;
     new form_hidden($form3, 'custom', $id);
     if ($returl != '') {
         new form_hidden($form3, 'returl', $_REQUEST['camila_returl']);
     }
     new form_filebox($form3, 'filename', camila_get_translation('camila.worktable.xls.choose'), 50, CAMILA_TMP_DIR);
     $sheet_list = '';
     for ($i = 0; $i < 10; $i++) {
         if ($i > 0) {
             $sheet_list .= ',';
         }
         $sheet_list .= $i . ';' . ($i + 1);
     }
     new form_static_listbox($form3, 'sheetnum', camila_get_translation('camila.worktable.xls.sheetnum'), $sheet_list);
     $success = true;
     if ($form3->process()) {
         $filename = $form3->fields['filename']->value[0];
         $sheetnum = $form3->fields['sheetnum']->value;
         $result = $_CAMILA['db']->Execute('select short_title, scriptname, tablename, filename, sheetnum from ' . CAMILA_TABLE_WORKT . ' where id=' . $_CAMILA['db']->qstr($id));
         if ($result === false) {
             camila_error_page(camila_get_translation('camila.sqlerror') . ' ' . $_CAMILA['db']->ErrorMsg());
         }
         $table = $result->fields['tablename'];
         $worktablename = $result->fields['short_title'];
         $worktablescript = $result->fields['scriptname'];
         if ($filename == '' && $result->fields['filename'] != '') {
             $filename = $result->fields['filename'];
             $sheetnum = $result->fields['sheetnum'];
         }
         if ($filename != '') {
             require_once CAMILA_LIB_DIR . 'php-excel-reader/excel_reader2.php';
             $data = new Spreadsheet_Excel_Reader(CAMILA_TMP_DIR . '/' . $filename);
             $excelColNames = array();
             $i = 0;
             while ($data->val(1, $i + 1, $sheetnum) != '') {
                 $name = $data->val(1, $i + 1, $sheetnum);
                 $excelColNames[$i] = camila_strtoupper_utf8(isUTF8($name) ? $name : utf8_encode($name));
                 $i++;
             }
             $result = $_CAMILA['db']->Execute('select * from ' . CAMILA_TABLE_WORKC . ' where (wt_id=' . $_CAMILA['db']->qstr($id) . ' and is_deleted<>' . $_CAMILA['db']->qstr('y') . ') order by sequence');
             if ($result === false) {
                 camila_error_page(camila_get_translation('camila.sqlerror') . ' ' . $_CAMILA['db']->ErrorMsg());
             }
             $fields = array();
             $types = array();
             $defVals = array();
             $forceCase = array();
             $orig_types = array();
             $fieldMapping = array();
             $forceArr = camila_get_translation_array('camila.worktable.options.force');
             $count = 0;
             while (!$result->EOF) {
                 $colName = $result->fields['col_name'];
                 $name = camila_strtoupper_utf8($result->fields['name']);
                 $fieldMapping[$colName] = isUTF8($name) ? $name : utf8_encode($name);
                 $fields[$count] = $colName;
                 $types[$count] = $result->fields['type'];
                 $orig_types[$count] = $result->fields['orig_type'];
                 $defVals[$count] = $result->fields['default_value'];
                 $forceCase[$count] = $result->fields['force_case'];
                 $count++;
                 $result->MoveNext();
             }
             $successCount = 0;
             $failCount = 0;
             //db fields
             for ($i = 2; $i <= $data->rowcount($sheetnum); $i++) {
                 $record = array();
                 $emptyrow = true;
                 //db fields
                 reset($fields);
                 foreach ($fields as $k => $v) {
                     //k  Field position into database
                     //k2 Position in Excel file
                     $k2 = array_search($fieldMapping[$v], $excelColNames);
                     //Is it in Excel file?
                     if ($k2 !== false) {
                         $excelColName = camila_strtoupper_utf8($data->value(1, $k2 + 1, $sheetnum));
                         //$excelColName = $v;
                         $worktableColName = array_search($excelColName, $fieldMapping);
                         $worktableColName = $v;
                         if ($worktableColName != '') {
                             if ($types[$k] == 'date' && $data->val($i, $k2 + 1, $sheetnum) != '') {
                                 $numValue = $data->sheets[$sheetnum]['cellsInfo'][$i][$k2 + 1]['raw'];
                                 $utcDays = floor($numValue - ($data->nineteenFour ? SPREADSHEET_EXCEL_READER_UTCOFFSETDAYS1904 : SPREADSHEET_EXCEL_READER_UTCOFFSETDAYS));
                                 $utcValue = $utcDays * SPREADSHEET_EXCEL_READER_MSINADAY;
                                 $dateinfo = gmgetdate($utcValue);
                                 $fractionalDay = $numValue - floor($numValue) + 1.0E-7;
                                 // The .0000001 is to fix for php/excel fractional diffs
                                 $totalseconds = floor(SPREADSHEET_EXCEL_READER_MSINADAY * $fractionalDay);
                                 $secs = $totalseconds % 60;
                                 $totalseconds -= $secs;
                                 $hours = floor($totalseconds / (60 * 60));
                                 $mins = floor($totalseconds / 60) % 60;
                                 $dt = date('Y-m-d', mktime($hours, $mins, $secs, $dateinfo["mon"], $dateinfo["mday"], $dateinfo["year"]));
                                 $record[$worktableColName] = $_CAMILA['db']->BindDate($dt);
                             } elseif ($orig_types[$k] == 'number' && $data->sheets[$sheetnum]['cellsInfo'][$i][$k2 + 1]['raw'] != '') {
                                 $record[$worktableColName] = $data->sheets[$sheetnum]['cellsInfo'][$i][$k2 + 1]['raw'];
                             } elseif ($types[$k] == 'hyperlink' && $data->hyperlink($i, $k2 + 1, $sheetnum) != '') {
                                 //$record[$worktableColName] = '<a href="' . $data->hyperlink($i, $k2+1, $sheetnum) . '" target="_blank">' . $data->value($i, $k2+1, $sheetnum) . '</a>';
                                 $record[$worktableColName] = $data->hyperlink($i, $k2 + 1, $sheetnum);
                             } else {
                                 $record[$worktableColName] = $data->value($i, $k2 + 1, $sheetnum);
                             }
                             if ($defVals[$k] != '' && $record[$worktableColName] == '') {
                                 $record[$worktableColName] = camila_parse_default_expression($defVals[$k], '_camila_seq_num_', true);
                             }
                             if ($record[$worktableColName] != '') {
                                 if ($forceCase[$k] == 'upper') {
                                     $record[$worktableColName] = mb_strtoupper($record[$worktableColName], 'UTF-8');
                                 }
                                 if ($forceCase[$k] == 'lower') {
                                     $record[$worktableColName] = mb_strtolower($record[$worktableColName], 'UTF-8');
                                 }
                                 $emptyrow = false;
                             }
                         }
                     } else {
                         if ($defVals[$k] != '') {
                             $record[$fields[$k]] = camila_parse_default_expression($defVals[$k], '_camila_seq_num_', true);
                         }
                     }
                 }
                 if (!$emptyrow) {
                     $now = $_CAMILA['db']->BindTimeStamp(gmdate("Y-m-d H:i:s", time()));
                     $id = $_CAMILA['db']->GenID('worktableseq', 100000);
                     foreach ($record as $k => $v) {
                         $record[$k] = str_replace('_camila_seq_num_', $id, $v);
                     }
                     $record['id'] = $id;
                     $record['created'] = $now;
                     $record['created_by'] = $_CAMILA['user'];
                     $record['created_src'] = 'import';
                     $record['created_by_surname'] = $_CAMILA['user_surname'];
                     $record['created_by_name'] = $_CAMILA['user_name'];
                     $record['last_upd'] = $now;
                     $record['last_upd_by'] = $_CAMILA['user'];
                     $record['last_upd_src'] = 'import';
                     $record['last_upd_by_surname'] = $_CAMILA['user_surname'];
                     $record['last_upd_by_name'] = $_CAMILA['user_name'];
                     $record['mod_num'] = 0;
                     $insertSQL = $_CAMILA['db']->AutoExecute($table, $record, 'INSERT');
                     if (!$insertSQL) {
                         //camila_information_text(camila_get_translation('camila.worktable.db.importerror'));
                         $failCount++;
                         $success = false;
                     } else {
                         $successCount++;
                     }
                 }
             }
         }
         camila_information_text(camila_get_translation('camila.worktable.db.importedrows') . ': ' . $successCount);
         camila_information_text(camila_get_translation('camila.worktable.db.skippedrows') . ': ' . $failCount);
         @unlink(CAMILA_TMP_DIR . '/' . $filename);
     } else {
         $result = $_CAMILA['db']->Execute('select tablename, filename, sheetnum from ' . CAMILA_TABLE_WORKT . ' where id=' . $_CAMILA['db']->qstr($id));
         if ($result === false) {
             camila_error_page(camila_get_translation('camila.sqlerror') . ' ' . $_CAMILA['db']->ErrorMsg());
         }
         $filename = $result->fields['filename'];
         //            if ($filename != '') {
         $myText = new CHAW_text(camila_get_translation('camila.wizard.choosefileforimport'));
         $_CAMILA['page']->add_text($myText);
         $form3->draw();
         $success = false;
         //	    }
     }
     if ($success) {
         if ($worktablename != '') {
             $myLink = new CHAW_link($worktablename, $worktablescript);
             $myLink->set_br(0);
             $_CAMILA['page']->add_link($myLink);
             $myText = new CHAW_text(' - ' . camila_get_translation('camila.worktable.db.importok'));
             $_CAMILA['page']->add_text($myText);
         } else {
             $myText = new CHAW_text(camila_get_translation('camila.wizard.configurationapplied'));
             $_CAMILA['page']->add_text($myText);
         }
     }
 }
Beispiel #3
0
 function create_page()
 {
     global $_CAMILA;
     if ($_REQUEST['camila_export_action'] == '' || $_REQUEST['camila_export_action'] == 'download' || $_REQUEST['camila_export_action'] == 'sendmail') {
         $fname = tempnam(CAMILA_TMP_DIR, 'export.xls');
     } else {
         if (!$this->camila_export_file_exists || $_REQUEST['camila_export_overwrite'] == 'y') {
             $fname = $this->camila_export_get_dir() . $this->camila_export_filename();
         } else {
             $fname = tempnam(CAMILA_TMP_DIR, 'export.xls');
         }
     }
     $workbook =& new Spreadsheet_Excel_Writer_Workbook($fname);
     $workbook->setTempDir(CAMILA_TMP_DIR);
     $workbook->setVersion(8);
     $dWorksheet =& $workbook->addworksheet($_CAMILA['page_short_title'] . ' - ' . camila_get_translation('camila.worktable.worksheet.data'));
     $i = 0;
     $m = camila_get_translation('camila.dateformat.monthpos');
     $d = camila_get_translation('camila.dateformat.daypos');
     $y = camila_get_translation('camila.dateformat.yearpos');
     $date_format =& $workbook->addFormat();
     $fmt = str_replace(array('d', 'm', 'y'), array('dd', 'mm', 'yyyy'), strtolower($_CAMILA['date_format']));
     $date_format->setNumFormat($fmt);
     $dataFound = false;
     while (isset($this->element[$i])) {
         $page_element = $this->element[$i];
         switch ($page_element->get_elementtype()) {
             case HAW_TABLE:
                 $table = $this->element[$i];
                 $row = $table->row[0];
                 for ($b = 0; $b < $row->number_of_columns; $b++) {
                     $column = $row->column[$b];
                     if (is_object($column) && $column->get_elementtype() == HAW_PLAINTEXT) {
                         $text = $column->get_text();
                     }
                     if (is_object($column) && $column->get_elementtype() == HAW_LINK) {
                         $text = $column->get_label();
                     }
                     $dWorksheet->writeString($a, $b, isUTF8($text) ? utf8_decode($text) : $text);
                 }
                 if (!$_CAMILA['page']->camila_worktable || $_CAMILA['page']->camila_worktable && ($_REQUEST['camila_worktable_export'] == 'all' || $_REQUEST['camila_worktable_export'] == 'dataonly')) {
                     for ($a = 1; $a < $table->number_of_rows; $a++) {
                         $row = $table->row[$a];
                         $dataFound = true;
                         for ($b = 0; $b < $row->number_of_columns; $b++) {
                             $column = $row->column[$b];
                             if (is_object($column) && $column->get_elementtype() == HAW_LINK) {
                                 $text = $column->get_label();
                                 $url = $column->get_url();
                                 $dWorksheet->writeUrl($a, $b, $url, $text);
                             } else {
                                 if (is_object($column) && $column->get_elementtype() == HAW_PLAINTEXT) {
                                     $text = $column->get_text();
                                 }
                                 switch ($column->metatype) {
                                     case 'I':
                                     case 'N':
                                         if ($text != '') {
                                             $dWorksheet->writeNumber($a, $b, intval($text));
                                         }
                                         break;
                                     case 'D':
                                         if ($text != '') {
                                             $dWorksheet->writeNumber($a, $b, $this->xl_date_list(intval(substr($text, $y, 4)), intval(substr($text, $m, 2)), intval(substr($text, $d, 2))), $date_format);
                                         }
                                         break;
                                     default:
                                         $dWorksheet->writeString($a, $b, isUTF8($text) ? utf8_decode($text) : $text);
                                 }
                             }
                         }
                     }
                 }
                 break;
         }
         $i++;
     }
     if ($_CAMILA['page']->camila_worktable && ($_REQUEST['camila_worktable_export'] == 'all' || $_REQUEST['camila_worktable_export'] == 'confonly')) {
         $worksheet =& $workbook->addworksheet($_CAMILA['page_short_title'] . ' - ' . camila_get_translation('camila.worktable.worksheet.conf'));
         $aLeft =& $workbook->addformat();
         $aLeft->setAlign('left');
         $opt = array();
         $opt[] = camila_get_translation('camila.worktable.field.sequence');
         $opt[] = camila_get_translation('camila.worktable.field.name.abbrev');
         $opt[] = camila_get_translation('camila.worktable.field.type');
         $opt[] = camila_get_translation('camila.worktable.field.listofvalues');
         $opt[] = camila_get_translation('camila.worktable.field.maxlength');
         $opt[] = camila_get_translation('camila.worktable.field.required');
         $opt[] = camila_get_translation('camila.worktable.field.defaultval');
         $opt[] = camila_get_translation('camila.worktable.field.readonly');
         $opt[] = camila_get_translation('camila.worktable.field.visible');
         $opt[] = camila_get_translation('camila.worktable.field.force');
         $opt[] = camila_get_translation('camila.worktable.field.unique');
         $opt[] = camila_get_translation('camila.worktable.field.options');
         $opt[] = camila_get_translation('camila.worktable.field.autosuggestwtname');
         $opt[] = camila_get_translation('camila.worktable.field.autosuggestwtcolname');
         $opt[] = '';
         $opt[] = camila_get_translation('camila.worktable.configuration');
         $opt[] = camila_get_translation('camila.worktable.name');
         $opt[] = camila_get_translation('camila.worktable.desc');
         $opt[] = camila_get_translation('camila.worktable.order.by');
         $opt[] = camila_get_translation('camila.worktable.order.dir');
         $opt[] = camila_get_translation('camila.worktable.canupdate');
         $opt[] = camila_get_translation('camila.worktable.caninsert');
         $opt[] = camila_get_translation('camila.worktable.candelete');
         $opt[] = camila_get_translation('camila.worktable.category');
         foreach ($opt as $key => $value) {
             $text = $opt[$key];
             $worksheet->writeString(intval($key) + 1, $o, isUTF8($text) ? utf8_decode($text) : $text);
         }
         $worksheet->setColumn(0, 0, 30);
         $id = substr($_SERVER['PHP_SELF'], 12, -4);
         $result = $_CAMILA['db']->Execute('select * from ' . CAMILA_TABLE_WORKC . ' where (wt_id=' . $_CAMILA['db']->qstr($id) . ' and is_deleted<>' . $_CAMILA['db']->qstr('y') . ') order by sequence');
         if ($result === false) {
             camila_error_page(camila_get_translation('camila.sqlerror') . ' ' . $_CAMILA['db']->ErrorMsg());
         }
         $yesNoArr = camila_get_translation_array('camila.worktable.options.noyes');
         $fieldTypeArr = camila_get_translation_array('camila.worktable.options.fieldtype');
         $forceArr = camila_get_translation_array('camila.worktable.options.force');
         $orderDirArr = camila_get_translation_array('camila.worktable.options.order.dir');
         $colArray = array();
         $count = 1;
         while (!$result->EOF) {
             $colArray[$result->fields['col_name']] = $result->fields['name'];
             $text = $result->fields['name'];
             $worksheet->writeString(0, $count, isUTF8($text) ? utf8_decode($text) : $text);
             if ($_REQUEST['camila_worktable_export'] == 'all' && !$dataFound) {
                 $dWorksheet->writeString(0, $count - 1, isUTF8($text) ? utf8_decode($text) : $text);
             }
             $text = $result->fields['sequence'];
             $worksheet->writeNumber(1, $count, isUTF8($text) ? utf8_decode($text) : $text, $aLeft);
             $text = $result->fields['name_abbrev'];
             $worksheet->writeString(2, $count, isUTF8($text) ? utf8_decode($text) : $text);
             $text = $fieldTypeArr[$result->fields['type']];
             $worksheet->writeString(3, $count, isUTF8($text) ? utf8_decode($text) : $text);
             $text = $result->fields['listbox_options'];
             $worksheet->writeString(4, $count, isUTF8($text) ? utf8_decode($text) : $text);
             $text = $result->fields['maxlength'];
             $worksheet->writeNumber(5, $count, isUTF8($text) ? utf8_decode($text) : $text, $aLeft);
             $text = $yesNoArr[$result->fields['required']];
             $worksheet->writeString(6, $count, isUTF8($text) ? utf8_decode($text) : $text);
             $text = $result->fields['default_value'];
             $worksheet->writeString(7, $count, isUTF8($text) ? utf8_decode($text) : $text);
             $text = $text = $yesNoArr[$result->fields['readonly']];
             $worksheet->writeString(8, $count, isUTF8($text) ? utf8_decode($text) : $text);
             $text = $text = $yesNoArr[$result->fields['visible']];
             $worksheet->writeString(9, $count, isUTF8($text) ? utf8_decode($text) : $text);
             $text = $forceArr[$result->fields['force_case']];
             $worksheet->writeString(10, $count, isUTF8($text) ? utf8_decode($text) : $text);
             $text = $yesNoArr[$result->fields['must_be_unique']];
             $worksheet->writeString(11, $count, isUTF8($text) ? utf8_decode($text) : $text);
             $text = $result->fields['field_options'];
             $worksheet->writeString(12, $count, isUTF8($text) ? utf8_decode($text) : $text);
             $text = $result->fields['autosuggest_wt_name'];
             $worksheet->writeString(13, $count, isUTF8($text) ? utf8_decode($text) : $text);
             $text = $result->fields['autosuggest_wt_colname'];
             $worksheet->writeString(14, $count, isUTF8($text) ? utf8_decode($text) : $text);
             $count++;
             $result->MoveNext();
         }
         $worksheet->setColumn(1, $count - 1, 15);
         $result = $_CAMILA['db']->Execute('select * from ' . CAMILA_TABLE_WORKT . ' where id=' . $_CAMILA['db']->qstr($id));
         if ($result === false) {
             camila_error_page(camila_get_translation('camila.sqlerror') . ' ' . $_CAMILA['db']->ErrorMsg());
         }
         $text = $result->fields['short_title'];
         $worksheet->writeString(17, 1, isUTF8($text) ? utf8_decode($text) : $text);
         $text = $result->fields['full_title'];
         $worksheet->writeString(18, 1, isUTF8($text) ? utf8_decode($text) : $text);
         $text = $colArray[$result->fields['order_field']];
         $worksheet->writeString(19, 1, isUTF8($text) ? utf8_decode($text) : $text);
         $text = $orderDirArr[$result->fields['order_dir']];
         $worksheet->writeString(20, 1, isUTF8($text) ? utf8_decode($text) : $text);
         $text = $yesNoArr[$result->fields['canupdate']];
         $worksheet->writeString(21, 1, isUTF8($text) ? utf8_decode($text) : $text);
         $text = $yesNoArr[$result->fields['caninsert']];
         $worksheet->writeString(22, 1, isUTF8($text) ? utf8_decode($text) : $text);
         $text = $yesNoArr[$result->fields['candelete']];
         $worksheet->writeString(23, 1, isUTF8($text) ? utf8_decode($text) : $text);
         $text = $result->fields['category'];
         $worksheet->writeString(24, 1, isUTF8($text) ? utf8_decode($text) : $text);
         $text = camila_get_translation('camila.worktable.bookmarks');
         $worksheet->writeString(16, 2, isUTF8($text) ? utf8_decode($text) : $text);
         $query = 'select base_url,url,title from ' . CAMILA_APPLICATION_PREFIX . 'camila_bookmarks where base_url=' . $_CAMILA['db']->qstr('cf_worktable' . $id . '.php') . ' order by sequence';
         $result = $_CAMILA['db']->Execute($query);
         if ($result === false) {
             camila_error_page(camila_get_translation('camila.sqlerror') . ' ' . $_CAMILA['db']->ErrorMsg());
         }
         $i = 0;
         while (!$result->EOF) {
             $i++;
             $text = $result->fields['title'];
             $worksheet->writeString(16 + $i, 2, isUTF8($text) ? utf8_decode($text) : $text);
             $url = parse_url($result->fields['url'], PHP_URL_QUERY);
             $qArr = $this->parse_query_string($url);
             $text = $qArr['filter'];
             $worksheet->writeString(16 + $i, 3, isUTF8($text) ? utf8_decode($text) : $text);
             $result->MoveNext();
         }
     }
     if ($_CAMILA['page']->camila_worktable && !$dataFound && $_REQUEST['camila_worktable_export'] == 'dataonly') {
         $id = substr($_SERVER['PHP_SELF'], 12, -4);
         $result = $_CAMILA['db']->Execute('select * from ' . CAMILA_TABLE_WORKC . ' where (wt_id=' . $_CAMILA['db']->qstr($id) . ' and is_deleted<>' . $_CAMILA['db']->qstr('y') . ') order by sequence');
         if ($result === false) {
             camila_error_page(camila_get_translation('camila.sqlerror') . ' ' . $_CAMILA['db']->ErrorMsg());
         }
         $count = 1;
         while (!$result->EOF) {
             $text = $result->fields['name'];
             $dWorksheet->writeString(0, $count - 1, isUTF8($text) ? utf8_decode($text) : $text);
             $count++;
             $result->MoveNext();
         }
     }
     $workbook->close();
     if ($_REQUEST['camila_export_action'] == '' || $_REQUEST['camila_export_action'] == 'download') {
         header("Content-Type: application/x-msexcel; name=\"" . $this->camila_export_safe_filename() . '.' . $this->camila_export_get_ext() . "\"");
         header("Content-Disposition: attachment; filename=\"" . $this->camila_export_safe_filename() . '.' . $this->camila_export_get_ext() . "\"");
     }
     $fh = fopen($fname, "rb");
     if ($_REQUEST['camila_export_action'] == '' || $_REQUEST['camila_export_action'] == 'download') {
         fpassthru($fh);
         unlink($fname);
     }
     if ($_REQUEST['camila_export_action'] == 'sendmail') {
         global $_CAMILA;
         require_once CAMILA_LIB_DIR . 'phpmailer/class.phpmailer.php';
         $mail = new PHPMailer();
         if (CAMILA_MAIL_IS_SMTP) {
             $mail->IsSMTP();
         }
         $mail->Host = CAMILA_MAIL_HOST;
         $mail->SMTPAuth = CAMILA_MAIL_SMTP_AUTH;
         $mail->From = CAMILA_WORKTABLE_CONFIRM_VIA_MAIL_FROM;
         $mail->FromName = CAMILA_WORKTABLE_CONFIRM_VIA_MAIL_FROM_NAME;
         $mail->AddAttachment($fname, 'file.xls');
         $mail->AddAddress(CAMILA_WORKTABLE_CONFIRM_VIA_MAIL_TO);
         //$mail->AddCC(CAMILA_WORKTABLE_CONFIRM_VIA_MAIL_CC, CAMILA_WORKTABLE_CONFIRM_VIA_MAIL_CC);
         $mail->IsHTML(false);
         $mail->Subject = CAMILA_WORKTABLE_CONFIRM_VIA_MAIL_SUBJECT;
         $text = camila_get_translation('camila.worktable.confirm') . " - " . camila_get_translation('camila.login.username') . ': ' . $_CAMILA['user_name'];
         $mail->Body = $text;
         $mail->AltBody = $text;
         $mail->Send();
         unlink($fname);
     }
 }