public static function config() { echo \GCore\Helpers\Html::formStart('action_config file_download_action_config', 'file_download_action_config_{N}'); echo \GCore\Helpers\Html::formSecStart(); echo \GCore\Helpers\Html::formLine('Form[extras][actions_config][{N}][path]', array('type' => 'text', 'label' => l_('CF_FILE_DOWNLOAD_PATH'), 'value' => \GCore\C::ext_path('chronoforms', 'front'), 'class' => 'XXL', 'sublabel' => l_('CF_FILE_DOWNLOAD_PATH_DESC'))); echo \GCore\Helpers\Html::formSecEnd(); echo \GCore\Helpers\Html::formEnd(); }
function edit() { $id = $this->Request->data('id', null); $this->Connection->id = $id; $connection = $this->Connection->load(); if (!empty($connection)) { $this->data = $connection; } $this->set(array('connection' => $connection)); //get tables list $tables = $this->Connection->dbo->getTablesList(); array_unshift($tables, ''); $this->set('tables', array_combine($tables, $tables)); if (!empty($connection['Connection']['extras']['ndb']['enabled'])) { $dbo_config = array('type' => $connection['Connection']['extras']['ndb']['driver'], 'host' => $connection['Connection']['extras']['ndb']['host'], 'name' => $connection['Connection']['extras']['ndb']['database'], 'user' => $connection['Connection']['extras']['ndb']['user'], 'pass' => $connection['Connection']['extras']['ndb']['password'], 'prefix' => $connection['Connection']['extras']['ndb']['prefix']); $tables = \GCore\Libs\Database::getInstance($dbo_config)->getTablesList(); array_unshift($tables, ''); $this->set('tables', array_combine($tables, $tables)); } //get blocks files $blocks_files = \GCore\Libs\Folder::getFiles(\GCore\C::ext_path('chronoconnectivity', 'admin') . 'blocks' . DS); $blocks = array(); $blocks_classes = array(); foreach ($blocks_files as $block) { $name = str_replace(array(\GCore\C::ext_path('chronoconnectivity', 'admin') . 'blocks' . DS, '.php'), '', $block); $blocks_classes[] = $class = '\\GCore\\Admin\\Extensions\\Chronoconnectivity\\Blocks\\' . \GCore\Libs\Str::camilize($name); $blocks[$class::$name] = $class::$title; } $this->set('blocks', $blocks); $this->set('blocks_classes', $blocks_classes); $rules = $this->Group->find('list', array('fields' => array('id', 'title'))); $rules['owner'] = 'Owner'; $this->set('rules', $rules); $actions_list = array('index', 'view', 'edit', 'save', 'save_list', 'toggle', 'delete'); $standard_actions = array('view', 'edit'); foreach ($standard_actions as $standard_action) { if (!isset($this->data['Connection']['extras']['front']['actions'][$standard_action])) { $this->data['Connection']['extras']['front']['actions'][$standard_action] = array(); } if (!isset($this->data['Connection']['extras']['admin']['actions'][$standard_action])) { $this->data['Connection']['extras']['admin']['actions'][$standard_action] = array(); } } $this->set('actions_list', $actions_list); $this->set('standard_actions', $standard_actions); $plugins_files = \GCore\Libs\Folder::getFiles(\GCore\C::ext_path('chronoconnectivity', 'admin') . 'plugins' . DS); $plugins = array(); $plugins_classes = array(); foreach ($plugins_files as $plugin) { $name = str_replace(array(\GCore\C::ext_path('chronoconnectivity', 'admin') . 'plugins' . DS, '.php'), '', $plugin); $plugins_classes[] = $class = '\\GCore\\Admin\\Extensions\\Chronoconnectivity\\Plugins\\' . \GCore\Libs\Str::camilize($name) . '\\' . \GCore\Libs\Str::camilize($name); $plugins[$class::$name] = $class::$title; } $this->set('plugins', $plugins); $this->set('plugins_classes', $plugins_classes); }
function execute(&$form, $action_id) { $config = $form->actions_config[$action_id]; $config = new \GCore\Libs\Parameter($config); //set the images path $upload_path = $config->get('upload_path', ''); if (!empty($upload_path)) { $upload_path = str_replace(array("/", "\\"), DS, $upload_path); if (substr($upload_path, -1) == DS) { $upload_path = substr_replace($upload_path, '', -1); } $upload_path = $upload_path . DS; $config->set('upload_path', $upload_path); } else { $upload_path = \GCore\C::ext_path('chronoforms', 'front') . 'uploads' . DS . $form->form['Form']['title'] . DS; } $image_file_name = $config->get('photo', ''); if (strpos($image_file_name, ',') !== false) { $image_file_names = explode(',', $image_file_name); } else { $image_file_names = array($image_file_name); } foreach ($image_file_names as $image_file_name) { //stop if the field name is not set or if the file data doesn't exist //if((strlen($image_file_name) == 0) || !isset($form->data[$image_file_name]) || !isset($form->files[$image_file_name]['path'])){ if (strlen($image_file_name) == 0 || !isset($form->files[$image_file_name])) { continue; } if ($form->files[$image_file_name] === array_values($form->files[$image_file_name])) { //array of files $reset = false; } else { $form->files[$image_file_name] = array($form->files[$image_file_name]); $reset = true; } foreach ($form->files[$image_file_name] as $k => $image) { // Common parameters $photo = $image['name']; //$form->data[$image_file_name]; $filein = $image['path']; $file_info = pathinfo($filein); $form->debug[$action_id][self::$title][] = $form->files[$image_file_name][$k]['thumb_big'] = $this->processSize('big', $form, $config, $form->actions_config[$action_id], $photo, $filein, $upload_path, $file_info); // treatment of the medium image $form->debug[$action_id][self::$title][] = $form->files[$image_file_name][$k]['thumb_med'] = $this->processSize('med', $form, $config, $form->actions_config[$action_id], $photo, $filein, $upload_path, $file_info); // treatment of the small image $form->debug[$action_id][self::$title][] = $form->files[$image_file_name][$k]['thumb_small'] = $this->processSize('small', $form, $config, $form->actions_config[$action_id], $photo, $filein, $upload_path, $file_info); if ($config->get('delete_original')) { unlink($filein); } } if ($reset) { $form->files[$image_file_name] = $form->files[$image_file_name][0]; } } }
function index() { //apply updates $sql = file_get_contents(\GCore\C::ext_path('chronoforms', 'admin') . 'sql' . DS . 'install.chronoforms.sql'); $queries = \GCore\Libs\Database::getInstance()->split_sql($sql); foreach ($queries as $query) { \GCore\Libs\Database::getInstance()->exec(\GCore\Libs\Database::getInstance()->_prefixTable($query)); } $session = \GCore\Libs\Base::getSession(); $session->setFlash('success', l_('CF_DB_TABLES_INSTALLED')); $this->redirect(r_('index.php?ext=chronoforms')); }
function demos() { $session = \GCore\Libs\Base::getSession(); $demos_file = \GCore\C::ext_path('chronoforms', 'admin') . DS . 'demos' . DS . 'demos.cf5bak'; if (!$demos_file) { $session->setFlash('error', l_('CF_FORMS_RESTORE_ERROR')); } else { $data = file_get_contents($demos_file); //\GCore\Libs\File::delete($path.DS.$files['cfbackup']['name']); $forms = unserialize(base64_decode(trim($data))); if (!empty($forms)) { foreach ($forms as $form) { if (isset($form['Form']['id'])) { $form['Form']['id'] = null; //$form['Form']['published'] = 0; $this->Form->save($form); } } } $session->setFlash('success', l_('CF_FORMS_RESTORED')); $this->redirect(r_('index.php?ext=chronoforms')); } }
function execute(&$form, $action_id) { $config = $form->actions_config[$action_id]; $this->config = $config = new \GCore\Libs\Parameter($config); if ((bool) $config->get('enabled', 0) === false) { return; } $upload_path = $config->get('upload_path', ''); if (!empty($upload_path)) { $upload_path = str_replace(array("/", "\\"), DS, $upload_path); if (substr($upload_path, -1) == DS) { $upload_path = substr_replace($upload_path, '', -1); } $upload_path = $upload_path . DS; $config->set('upload_path', $upload_path); } else { $upload_path = \GCore\C::ext_path('chronoforms', 'front') . 'uploads' . DS . $form->form['Form']['title'] . DS; } $this->upload_path = $upload_path; //check path is correct if (!is_dir($this->upload_path) or !is_writable(realpath($this->upload_path))) { //$form->errors[] = "Unable to write to upload directory."; //$this->events['fail'] = 1; //return; } if (!file_exists($this->upload_path . DS . 'index.html')) { if (!\GCore\Libs\Folder::create($this->upload_path)) { $form->errors[] = "Couldn't create upload directory: " . $this->upload_path; $this->events['fail'] = 1; return; } $dummy_c = '<html><body bgcolor="#ffffff"></body></html>'; if (!\GCore\Libs\File::write($this->upload_path . DS . 'index.html', $dummy_c)) { $form->errors[] = "Couldn't create upload directory index file."; $this->events['fail'] = 1; return; } } $files_array = explode("\n", trim($config->get('files', ''))); //get array fields $array_fields = array(); if (trim($config->get('array_fields', ''))) { $array_fields = explode(',', trim($config->get('array_fields', ''))); } foreach ($files_array as $file_string) { if (strpos($file_string, ':') !== false) { $file_data = explode(':', trim($file_string)); $file_extensions = explode($config->get('extensions_separator', '-'), $file_data[1]); //convert all extensions to lower case foreach ($file_extensions as $k => $file_extension) { $file_extensions[$k] = strtolower($file_extension); } //get the posted file details $field_name = $file_data[0]; if (empty($_FILES[$field_name])) { continue; } $file_post = $_FILES[$field_name]; if (in_array($field_name, $array_fields) and !empty($file_post['name']) and $file_post['name'] === array_values($file_post['name'])) { foreach ($file_post['name'] as $k => $v) { $uploaded_file_data = $this->processUpload($form, array('name' => $file_post['name'][$k], 'tmp_name' => $file_post['tmp_name'][$k], 'error' => $file_post['error'][$k], 'size' => $file_post['size'][$k]), $file_data[0], $file_extensions); if (is_array($uploaded_file_data)) { $form->files[$field_name][] = $uploaded_file_data; $form->data[$field_name][] = $uploaded_file_data['name']; } elseif ($uploaded_file_data === false) { return false; } } } else { $uploaded_file_data = $this->processUpload($form, $file_post, $field_name, $file_extensions); if (is_array($uploaded_file_data)) { $form->files[$field_name] = $uploaded_file_data; $form->data[$field_name] = $uploaded_file_data['name']; } elseif ($uploaded_file_data === false) { return false; } } } } }
function __call($name, $arguments = array()) { if (isset($this->connection['Connection']['extras'][$this->area]['actions'][$name]['code'])) { //$this->view = 'custom_act'; $this->view = \GCore\C::ext_path('chronoconnectivity', 'admin') . 'views' . DS . 'lists' . DS . 'custom_act.php'; $this->set('act_name', $name); } $this->set('connection', $this->connection); $this->set('area', $this->area); }
function execute(&$form, $action_id){ $config = $form->actions_config[$action_id]; $config = new \GCore\Libs\Parameter($config); $content = $config->get('content', ""); ob_start(); eval('?>'.$content); $output = ob_get_clean(); //if the content box was empty, display the form output if(empty($output)){ $output = $form->form_output; } $output = \GCore\Libs\Str::replacer($output, $form->data); //begin tcpdf code require_once('tcpdf/config/lang/eng.php'); require_once('tcpdf/tcpdf.php'); // create new PDF document $pdf = new \TCPDF($config->get('pdf_page_orientation', 'P'), PDF_UNIT, $config->get('pdf_page_format', 'A4'), true, 'UTF-8', false); //set protection if enabled if((bool)$config->get('enable_protection', 0) === true){ $owner_pass = ($config->get('owner_pass', "") ? $config->get('owner_pass', "") : null); $perms = (strlen($config->get('permissions', "")) > 0) ? explode(",", $config->get('permissions', "")) : array(); $pdf->SetProtection($perms, $config->get('user_pass', ""), $owner_pass, $config->get('sec_mode', ""), $pubkeys=null); } // set document information $pdf->SetCreator(PDF_CREATOR); $pdf->SetAuthor($config->get('pdf_author', 'PDF Author.')); $pdf->SetTitle($config->get('pdf_title', 'PDF Title Goes Here.')); $pdf->SetSubject($config->get('pdf_subject', 'Powered by Chronoforms + TCPDF')); $pdf->SetKeywords($config->get('pdf_keywords', 'Chronoforms, PDF Plugin, TCPDF, PDF, '.$form->form['Form']['title'])); // Willian // set header data, font and margins if((bool)$config->get((bool)$config->get('pdf_header_show', 1))){ if(strlen($config->get('pdf_title')) OR strlen($config->get('pdf_header'))){ $pdf->SetHeaderData(false, 0, $config->get('pdf_title', 'PDF Title Goes Here.'), $config->get('pdf_header', 'Powered by Chronoforms + TCPDF')); } $pdf->setHeaderFont(Array($config->get('pdf_header_font', 'helvetica'), '', (int)$config->get('pdf_header_font_size', 10))); $pdf->SetHeaderMargin($config->get('pdf_margin_header', 5)); $pdf->setPrintHeader(true); } else { $pdf->setPrintHeader(false); } // set footer font and margins if((bool)$config->get((bool)$config->get('pdf_footer_show', 1))){ $pdf->setFooterFont(Array($config->get('pdf_footer_font', 'helvetica'), '', (int)$config->get('pdf_footer_font_size', 8))); $pdf->SetFooterMargin($config->get('pdf_margin_footer', 10)); $pdf->setPrintFooter(true); } else { $pdf->setPrintFooter(false); } // set default monospaced font $pdf->SetDefaultMonospacedFont($config->get('pdf_monospaced_font', 'courier')); //set margins $pdf->SetMargins($config->get('pdf_margin_left', 15), $config->get('pdf_margin_top', 27), $config->get('pdf_margin_right', 15)); //set auto page breaks $pdf->SetAutoPageBreak(TRUE, $config->get('pdf_margin_bottom', 25)); //set image scale factor $pdf->setImageScale($config->get('pdf_image_scale_ratio', 1.25)); //set some language-dependent strings $pdf->setLanguageArray($l); // Willian // Mostrar/Esconder Cabeçalho $pdf->setPrintHeader((bool)$config->get('pdf_header_show', 1)); // Mostrar/Esconder Rodapé $pdf->setPrintHeader((bool)$config->get('pdf_footer_show', 1)); // --------------------------------------------------------- // set font $pdf->SetFont($config->get('pdf_body_font', 'courier'), '', (int)$config->get('pdf_body_font_size', 14)); // add a page $pdf->AddPage(); // create some HTML content $css = ""; $output = $css.$output; $html = $output; // output the HTML content $pdf->writeHTML($html, true, false, true, false, ''); // reset pointer to the last page $pdf->lastPage(); //Close and output PDF document if(isset($form->data['pdf_file_name']) && !empty($form->data['pdf_file_name'])){ $PDF_file_name = $form->data['pdf_file_name']; }else{ if(strlen(trim($config->get('pdf_file_name', ''))) > 0){ $PDF_file_name = trim($config->get('pdf_file_name', ''))."_".date('YmdHis'); }else{ $PDF_file_name = $form->form['Form']['title']."_".date('YmdHis'); } } $PDF_view = $config->get('pdf_view', 'I'); if(($PDF_view == 'F') || ($PDF_view == 'FI') || ($PDF_view == 'FD')){ jimport('joomla.utilities.error'); jimport('joomla.filesystem.file'); jimport('joomla.filesystem.folder'); $upload_path = $config->get('pdf_save_path'); if(!empty($upload_path)){ $upload_path = str_replace(array("/", "\\"), DS, $upload_path); if(substr($upload_path, -1) == DS){ $upload_path = substr_replace($upload_path, '', -1); } $upload_path = $upload_path.DS; $config->set('pdf_save_path', $upload_path); }else{ $upload_path = \GCore\C::ext_path('chronoforms', 'front').'pdfs'.DS.$form->form['Form']['title'].DS; } //check the save files path is ok if(!file_exists($upload_path.DS.'index.html')){ if(!\GCore\Libs\Folder::create($upload_path)){ $form->errors[] = "Couldn't create upload directory: ".$upload_path; $this->events['fail'] = 1; return; } $dummy_c = '<html><body bgcolor="#ffffff"></body></html>'; if(!\GCore\Libs\File::write($upload_path.DS.'index.html', $dummy_c)){ $form->errors[] = "Couldn't create upload directory index file."; $this->events['fail'] = 1; return; } } $PDF_file_path = $upload_path.$PDF_file_name.".pdf"; $pdf->Output($PDF_file_path, $PDF_view); //Try to generate an auto file link $site_link = \GCore\C::get('GCORE_FRONT_URL'); if(substr($site_link, -1) == "/"){ $site_link = substr_replace($site_link, '', -1); } if(strlen(trim($config->get('pdf_post_name', ''))) > 0){ $form->files[trim($config->get('pdf_post_name', ''))] = array('name' => $PDF_file_name.".pdf", 'path' => $PDF_file_path, 'size' => 0); $form->files[trim($config->get('pdf_post_name', ''))]['link'] = str_replace(array(\GCore\C::get('GCORE_FRONT_PATH'), DS), array($site_link, "/"), $upload_path.$PDF_file_name.".pdf"); $form->data[trim($config->get('pdf_post_name', ''))] = $PDF_file_name.".pdf"; $form->debug[$action_id][self::$title][] = $PDF_file_path.' has been saved correctly.'; } }else{ $pdf->Output($PDF_file_name.".pdf", $PDF_view); } if($PDF_view != 'F'){ @flush(); @ob_flush(); exit; } }
function execute(&$form, $action_id) { $config = $form->actions_config[$action_id]; $config = new \GCore\Libs\Parameter($config); if (!$config->get('enabled')) { return; } $data_path = trim($config->get('data_path', '')); $data = \GCore\Libs\Arr::getVal($form->data, explode('.', $data_path)); if (!empty($data) and is_array($data)) { $data = array_values($data); $first_data_record = $data[0]; $list_fields = strlen(trim($config->get('list_fields', ''))) ? explode(',', trim($config->get('list_fields', ''))) : array_keys($first_data_record); $list_headers = strlen(trim($config->get('list_headers', ''))) ? explode(',', trim($config->get('list_headers', ''))) : array_keys($first_data_record); $table_rows = ''; if (strlen(trim($config->get('before_headers', '')))) { $table_rows .= '<tr bgcolor="#fff">' . "\n"; $table_rows .= '<td>' . \GCore\Libs\Arr::getVal($form->data, explode('.', trim($config->get('before_headers', '')))) . '</td>' . "\n"; $table_rows .= '</tr>' . "\n"; } //add headers $table_rows .= '<tr bgcolor="#999999">' . "\n"; foreach ($list_headers as $k => $v) { $table_rows .= '<td style="color:white">' . $v . '</td>' . "\n"; } $table_rows .= '</tr>' . "\n"; //add data rows foreach ($data as $record) { $table_rows .= '<tr>' . "\n"; foreach ($record as $k => $v) { if (!in_array($k, $list_fields)) { continue; } $table_rows .= '<td valign="top" style="mso-number-format:\\@">' . $v . '</td>' . "\n"; } $table_rows .= '</tr>' . "\n"; } //finalize table $excel_table = "<table border='1'>" . $table_rows . "</table>"; if ($config->get('save_file', 0) == 1) { $save_path = $config->get('save_path', '') ? $config->get('save_path', '') : \GCore\C::ext_path('chronoforms', 'front') . 'exports' . DS . $form->form['Form']['title'] . DS; if (!file_exists($save_path . 'index.html')) { if (!mkdir($save_path, 0755, true)) { $form->debug[$action_id][self::$title] = "Couldn't create save folder: {$save_path}"; return; } file_put_contents($save_path . 'index.html', ''); } if ((bool) $config->get('add_bom', 0) === true) { $excel_table = "" . $excel_table; } $file_name = $config->get('file_name', 'cf_export.xls'); $saved = file_put_contents($save_path . $file_name, $excel_table); if (empty($saved)) { $form->debug[$action_id][self::$title] = "Couldn't create XLS file"; return; } if (strlen($config->get('post_file_name', '')) > 0) { $post_file_name = $config->get('post_file_name', ''); $form->data[$post_file_name] = $file_name; $form->files[$post_file_name] = array('name' => $file_name, 'path' => $save_path . $file_name, 'size' => filesize($save_path . $file_name)); //$form->files[$post_file_name]['link'] = $save_url.$file_name; } } else { //set headers header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Content-Type: application/force-download"); header("Content-Type: application/octet-stream"); header("Content-Type: application/download"); header("Content-Disposition: attachment;filename=" . $config->get('file_name', 'cf_export.xls')); header("Content-Transfer-Encoding: binary"); header('Content-Encoding: UTF-8'); //output data @ob_end_clean(); if ((bool) $config->get('add_bom', 0) === true) { echo ""; } echo $excel_table; exit; } } }