예제 #1
0
 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];
         }
     }
 }
예제 #2
0
 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;
                 }
             }
         }
     }
 }
예제 #3
0
파일: tcpdf.php 프로젝트: BillVGN/PortalPRP
	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;
		}
	}