fmsystem-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Fmsystem-commits] [7033] print and pdf for contracts


From: lars.nestas
Subject: [Fmsystem-commits] [7033] print and pdf for contracts
Date: Wed, 23 Feb 2011 07:12:30 +0000

Revision: 7033
          http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=7033
Author:   "lars.nestas"
Date:     2011-02-23 07:12:29 +0000 (Wed, 23 Feb 2011)
Log Message:
-----------
print and pdf for contracts

Modified Paths:
--------------
    trunk/rental/inc/class.uimakepdf.inc.php
    trunk/rental/templates/base/composite_list_partial.php
    trunk/rental/templates/base/pdf/css/contract.css
    trunk/rental/templates/base/pdf/rental_contract_form_hybler.php
    trunk/rental/templates/base/pdf/rental_contract_form_personalbolig.php

Added Paths:
-----------
    trunk/rental/inc/SnappyMedia.php
    trunk/rental/inc/SnappyPdf.php

Added: trunk/rental/inc/SnappyMedia.php
===================================================================
--- trunk/rental/inc/SnappyMedia.php                            (rev 0)
+++ trunk/rental/inc/SnappyMedia.php    2011-02-23 07:12:29 UTC (rev 7033)
@@ -0,0 +1,117 @@
+<?php
+
+/**
+* 
+*/
+abstract class SnappyMedia
+{
+    protected $executable;
+    protected $options = array();
+    protected $defaultExtension;
+    
+    /**
+     * Write the media to the standard output.
+     *
+     * @param string Url of the page
+     * @return void
+     */
+    public function output($url)
+    {
+      $file = tempnam(sys_get_temp_dir(), 'snappy') . '.' . 
$this->defaultExtension;
+      $ok = $this->save($url, $file);
+      readfile($file);
+      unlink($file);
+    }
+    
+    /**
+     * Save a url or file location to an image.
+     * Will create directories if needed.
+     *
+     * @param string Url of the page
+     * @param string Path of the future image
+     * @return boolean True if success
+     */
+    public function save($url, $path)
+    {
+        $command = $this->buildCommand($url, $path);
+        $basePath = dirname($path);
+        if(!is_dir($basePath)) {
+          mkdir($basePath, 0777, true);
+        }
+        if(file_exists($path)) {
+          unlink($path);
+        }
+        $ok = $this->exec($command);
+        return file_exists($path) && filesize($path);
+    }
+    
+    public function setExecutable($executable)
+    {
+        $this->executable = $executable;
+    }
+    
+    /**
+     * Set a wkhtmltoimage option. Be aware that option values are NOT 
validated
+     * and that it is your responsibility to validate user inputs.
+     * 
+     * @param string Option 
+     * @param string|array Value. Null to unset the option. 
+     * @return void
+     */
+    public function setOption($option, $value = null)
+    {
+        if(!array_key_exists($option, $this->options)) {
+            throw new Exception("Invalid option '$option'");
+        }
+        $this->options[$option] = $value;
+    }
+    
+    /**
+     * Merge wkhtmltoimage options (passed as an array) with current options
+     *
+     * @param array Array of options
+     * @return void
+     */
+    public function mergeOptions(array $options)
+    {
+        foreach($options as $key => $value) {
+            $this->setOption($key, $value);
+        }
+    }
+    
+    /**
+     * Return the command to wkhtmltoimage using the options attributes
+     *
+     * @param string Url or file location of the page to process
+     * @param string File location to the image-to-be
+     * @return string The command
+     */
+    protected function buildCommand($url, $path)
+    {
+        $command = $this->executable;
+
+        foreach($this->options as $key => $value) {
+            if(null !== $value && false !== $value) {
+                if(true === $value) {
+                    $command .= " --$key";
+                } elseif(is_array($value)) {
+                    foreach($value as $v) {
+                        $command .= " --$key $v";
+                    }
+                } else {
+                    $command .= " --$key $value";
+                }
+            }
+        }
+        
+        $command .= " \"$url\" \"$path\"";
+        
+        return $command;
+    }
+        
+    protected function exec($command)
+    {
+        return shell_exec($command);
+    }
+}
+?>
\ No newline at end of file

Added: trunk/rental/inc/SnappyPdf.php
===================================================================
--- trunk/rental/inc/SnappyPdf.php                              (rev 0)
+++ trunk/rental/inc/SnappyPdf.php      2011-02-23 07:12:29 UTC (rev 7033)
@@ -0,0 +1,19 @@
+<?php
+/**
+ * Use this class to transform a html/a url to a pdf
+ *
+ * @package Snappy
+ * @author Matthieu Bontemps<address@hidden>
+ */
+class SnappyPdf extends SnappyMedia
+{
+    protected $defaultExtension = 'pdf';
+    protected $options = array(
+        'ignore-load-errors' => null,                          // old v0.9
+        'lowquality' => true,
+        'username' => null,
+        'password' => null,
+    );
+    
+}
+?>
\ No newline at end of file

Modified: trunk/rental/inc/class.uimakepdf.inc.php
===================================================================
--- trunk/rental/inc/class.uimakepdf.inc.php    2011-02-22 08:15:04 UTC (rev 
7032)
+++ trunk/rental/inc/class.uimakepdf.inc.php    2011-02-23 07:12:29 UTC (rev 
7033)
@@ -16,6 +16,8 @@
        include_class('rental', 'price_item', 'inc/model/');
        include_class('rental', 'contract_price_item', 'inc/model/');
        include_class('rental', 'notification', 'inc/model/');
+       include 'SnappyMedia.php';
+       include 'SnappyPdf.php';
 
        class rental_uimakepdf extends rental_uicommon
        {
@@ -37,7 +39,8 @@
                        'remove_price_item'             => true,
                        'reset_price_item'              => true,
                        'download'              => true,
-                       'get_total_price'               => true
+                       'get_total_price'               => true,
+                       'makePDF'                               => true
                );
 
                public function __construct()
@@ -404,6 +407,31 @@
                        $contract_id = (int)phpgw::get_var('id');
                        return $this->viewedit(false, $contract_id);
                }
+               
+               /**
+                * Save a contract as PDF
+                */
+               public function makePDF()
+               {
+                       
+                       $myFile = "/opt/portico/pe/rental/tmp/testFile.html";
+                       $fh = fopen($myFile, 'w') or die("can't open file");
+                       $stringData = '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 
4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd";>';
+                       fwrite($fh, $stringData);
+                       $stringData = '<html><head><meta 
http-equiv="Content-Type" content="text/html; 
charset=UTF-8"><title></title></head><body>';
+                       fwrite($fh, $stringData);
+                       $stringData = $_SESSION['contract_html'];
+                       fwrite($fh, $stringData);
+                       $stringData = '</div></body></html>';
+                       fwrite($fh, $stringData);
+                       fclose($fh);
+                       echo $_SESSION['contract_html'];
+                        $_SESSION['contract_html'] = "";
+                        
+                       $snappy = new SnappyPdf;
+                       
$snappy->setExecutable('/opt/portico/pe/rental/wkhtmltopdf-i386'); // or 
whatever else
+                       
$snappy->save('/opt/portico/pe/rental/tmp/testFile.html', 
'/opt/portico/pe/rental/tmp/testFile.pdf');
+               }
 
                /**
                 * Edit a contract

Modified: trunk/rental/templates/base/composite_list_partial.php
===================================================================
--- trunk/rental/templates/base/composite_list_partial.php      2011-02-22 
08:15:04 UTC (rev 7032)
+++ trunk/rental/templates/base/composite_list_partial.php      2011-02-23 
07:12:29 UTC (rev 7033)
@@ -1,5 +1,16 @@
 <script type="text/javascript">
-       //Add listener resetting form: redirects browser to call index  again
+
+function checkAvailabitily()
+{
+       if(document.forms[0].availability_date_to.value == '')
+       {
+               document.forms[0].availability_date_to.value = 
document.forms[0].availability_date_from.value;
+               document.forms[0].availability_date_to.value_hidden = 
document.forms[0].availability_date_from_hidden.value
+       } 
+       return true;
+}
+
+//Add listener resetting form: redirects browser to call index  again
        YAHOO.util.Event.addListener(
                'ctrl_reset_button',
                'click',
@@ -38,6 +49,11 @@
                    sortable: false
                },
                {
+                       key: "status",
+                       label: "<?php echo lang('status') ?>",
+                   sortable: true
+               },
+               {
                        key: "actions",
                        hidden: true
                },
@@ -126,7 +142,7 @@
                        <option value="address" <?php echo ($s_type == 
'address') ? 'selected' : ''?>><?php echo lang('address') ?></option>
                        <option value="property_id" <?php echo ($s_type == 
'property_id') ? 'selected' : ''?>><?php echo lang('object_number') ?></option>
                </select>
-               <input type="submit" id="ctrl_search_button" value="<?php echo 
lang('search') ?>" />
+               <input type="submit" id="ctrl_search_button" value="<?php echo 
lang('search') ?>" onclick="javascript: checkAvailabitily();" />
                <input type="button" id="ctrl_reset_button" value="<?php echo 
lang('reset') ?>" />
        </fieldset>
 
@@ -135,9 +151,9 @@
                <h3><?php echo lang('filters') ?></h3>
                <label for="ctrl_toggle_active_rental_composites"><?php echo 
lang('availability') ?></label>
                <select name="is_active" id="<?php echo $list_id 
?>_ctrl_toggle_active_rental_composites">
+                       <option value="both" <?php echo ($status == 'both') ? 
'selected' : ''?>><?php echo lang('all') ?></option>
                        <option value="active" <?php echo ($status == 'active') 
? 'selected' : ''?>><?php echo lang('in_operation') ?></option>
                        <option value="non_active" <?php echo ($status == 
'non_active') ? 'selected' : ''?>><?php echo lang('out_of_operation') 
?></option>
-                       <option value="both" <?php echo ($status == 'both') ? 
'selected' : ''?>><?php echo lang('all') ?></option>
                </select>
                <select name="has_contract" id="<?php echo $list_id 
?>_ctrl_toggle_has_contract_rental_composites">
                        <option value="both" <?php echo ($status_contract == 
'both') ? 'selected' : ''?>><?php echo lang('all') ?></option>
@@ -145,7 +161,7 @@
                        <option value="has_no_contract" <?php echo 
($status_contract == 'has_no_contract') ? 'selected' : ''?>><?php echo 
lang('composite_has_no_contract') ?></option>
                </select>
                <label for="availability_period"><?php echo 
lang('availability_date')?></label>
-               <?php echo 
$GLOBALS['phpgw']->yuical->add_listener('availability_date', 
$availability_date); ?>
+               <?php echo 
$GLOBALS['phpgw']->yuical->add_listener('availability_date_from', 
$availability_date_from); ?>&nbsp;&ndash;&nbsp;<?php echo 
$GLOBALS['phpgw']->yuical->add_listener('availability_date_to', 
$availability_date_to); ?>
        </fieldset>
 </form>
 <?php

Modified: trunk/rental/templates/base/pdf/css/contract.css
===================================================================
--- trunk/rental/templates/base/pdf/css/contract.css    2011-02-22 08:15:04 UTC 
(rev 7032)
+++ trunk/rental/templates/base/pdf/css/contract.css    2011-02-23 07:12:29 UTC 
(rev 7033)
@@ -70,27 +70,34 @@
 }
 
 .section_header dd {
-       margin: 0 0 0 50px;
+       margin: 10px 0 5px 50px;
        padding: 0 0 0 0;
        font-weight: bold;
 }
 
-div {
-       padding-left: 10px;
+div.contract{
+       margin-top: 10px;
+       margin-right: 20px;
+       margin-left: 20px;
 }
 
 div.two_column {
        float: left;
        border: 2px solid;
-       width: 98%;
+       width: 100%;
        margin-bottom: 20px;
+       padding: 5px 5px 5px 5px;
+
 }
 
 div.one_column {
        float: left;
        border: 2px solid;
-       width: 98%;
-       margin-bottom: 20px;
+       width: 100%;
+       margin-bottom: 10px;
+       margin-top: 10px;
+       padding: 5px 5px 5px 5px;
+
 }
 
 div.left {
@@ -112,6 +119,7 @@
        width: 100%;
        font-size: 12px;
        font-family: arial;
+
 }
 
 table.header {
@@ -131,7 +139,7 @@
 }
 
 textarea {
-       width: 98%;
+       width: 100%;
        background-color: #ddffcc;
        margin-bottom: 10px;
 }

Modified: trunk/rental/templates/base/pdf/rental_contract_form_hybler.php
===================================================================
--- trunk/rental/templates/base/pdf/rental_contract_form_hybler.php     
2011-02-22 08:15:04 UTC (rev 7032)
+++ trunk/rental/templates/base/pdf/rental_contract_form_hybler.php     
2011-02-23 07:12:29 UTC (rev 7033)
@@ -6,9 +6,9 @@
 <style>
 <?php include "css/contract.css"?>
 </style>
+<div class="contract">
 
 
-
 <img 
src="http://www.nordlandssykehuset.no/getfile.php/NLSH_bilde%20og%20filarkiv/Internett/NLSH_logo_siste.jpg%20%28352x58%29.jpg";
 alt="Nordlanssykehuset logo" />
 <h1>Melding om inn/utflytting - Hybler</h1>
 
@@ -137,6 +137,7 @@
 <p>Kopi:</p>
 <p><span class="<?php echo $color_checkbox;?>"><input type="checkbox" 
name="checkb_HR" <?php echo $disabled; if(isset($_POST['checkb_HR']) || 
isset($_POST['checkb_HR_hidden'])) {echo 'checked="checked"';}?> 
/></span>Personalkontoret</p>
 <p><span class="<?php echo $color_checkbox;?>"><input type="checkbox" 
name="checkb_payroll_office"<?php echo $disabled; 
if(isset($_POST['checkb_payroll_office']) || 
isset($_POST['checkb_payroll_office_hidden'])) {echo 'checked="checked"';}?> 
/></span>Lønningskontoret</p>
+<br />
 <?php if (isset($_POST['preview']) ){ ?>
 <input type="submit" value="Rediger" name="edit"> 
 <input type="submit" value="Lagre som PDF" name="make_PDF"> 
@@ -145,3 +146,4 @@
 <input type="submit" value="Forhåndsvis" name="preview"> 
 <?php }?>
 </form>
+</div>

Modified: trunk/rental/templates/base/pdf/rental_contract_form_personalbolig.php
===================================================================
--- trunk/rental/templates/base/pdf/rental_contract_form_personalbolig.php      
2011-02-22 08:15:04 UTC (rev 7032)
+++ trunk/rental/templates/base/pdf/rental_contract_form_personalbolig.php      
2011-02-23 07:12:29 UTC (rev 7033)
@@ -1,4 +1,8 @@
 <?php 
+if (isset($_POST['preview']))
+{
+ob_start();
+}
 $date_format = 
$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'];
 $valuta_prefix = isset($config->config_data['currency_prefix']) ? 
$config->config_data['currency_prefix'] : '';
 $valuta_suffix = isset($config->config_data['currency_suffix']) ? 
$config->config_data['currency_suffix'] : '';
@@ -6,7 +10,7 @@
 <style>
 <?php include "css/contract.css"?>
 </style>
-
+<div class="contract">
 <img 
src="http://www.nordlandssykehuset.no/getfile.php/NLSH_bilde%20og%20filarkiv/Internett/NLSH_logo_siste.jpg%20%28352x58%29.jpg";
 alt="Nordlanssykehuset logo" />
 <h1>LEIEKONTRAKT</h1>
 <h2>FOR PERSONALBOLIG</h2>
@@ -18,14 +22,10 @@
 $color_checkbox = "checkbox_bg";
 $checkb_in_value = true;
 
-if (isset($_POST['preview']) )
+if (isset($_POST['preview']))
 {
        $disabled = 'disabled="disabled"';
        $color_checkbox = "";
-
-       echo "er post";
-       
-
 }
 
 if(isset($_POST['checkb_gab'])){?><input type="hidden" 
name="checkb_gab_hidden"  /><?php }
@@ -60,7 +60,7 @@
        <tr>
                <td>Nordlandssykehuset</td>
                <td bgcolor="#C0C0C0" width="120px">Navn:</td>
-               <td><?php echo $contract->get_party_name_as_list();?></td>
+               <td><?php echo $contract_party->get_first_name()." ". 
$contract_party->get_last_name();?></td>
        </tr>
        <tr>
                <td>Boligseksjonen</td>
@@ -94,7 +94,7 @@
        <dd>[hentes fra db] rom + <input type="checkbox" name="checkb_kitchen" 
<?php echo $disabled; if(isset($_POST['checkb_kitchen']) || 
isset($_POST['checkb_kitchen_hidden'])) {echo 'checked="checked"';}?>  /> 
kjøkken, <input type="checkbox" name="checkb_bath" <?php echo $disabled; 
if(isset($_POST['checkb_bath']) || isset($_POST['checkb_bath_hidden'])) {echo 
'checked="checked"';}?>  /> bad</dd>
        <dt><input type="checkbox" name="checkb_other" <?php echo $disabled; 
if(isset($_POST['checkb_other']) || isset($_POST['checkb_other_hidden'])) {echo 
'checked="checked"';}?>  /></dt>
        <dd>Annet: 
-<?php if (isset($_POST['preview']) )
+<?php if (isset($_POST['preview'])|| isset($_POST['make_PDF']) )
        {
                ?> <?php echo $_POST['other']?> <input type="hidden" 
name="other" value="<?php echo $_POST['other']?>" /> <?php
        }
@@ -106,7 +106,7 @@
        </dd>
        <dt><input type="checkbox" name="checkb_outer_space" <?php echo 
$disabled; if(isset($_POST['checkb_outer_space']) || 
isset($_POST['checkb_outer_space_hidden'])) {echo 'checked="checked"';}?>  
/></dt>
        <dd>Ytre rom: 
-<?php if (isset($_POST['preview']) )
+<?php if (isset($_POST['preview']) || isset($_POST['make_PDF']))
        {
                ?> <?php echo $_POST['outer_space']?> <input type="hidden" 
name="outer_space" value="<?php echo $_POST['outer_space']?>" /> <?php
        }
@@ -124,7 +124,7 @@
 <dl class="checkbox_list">
        <dt><input type="checkbox" name="checkb_limitations" <?php echo 
$disabled; if(isset($_POST['checkb_limitations']) || 
isset($_POST['checkb_limitations_hidden'])) {echo 'checked="checked"';}?>  
/></dt>
        <dd>Leier har ikke rett til å bruke:<br/>
-       <?php if (isset($_POST['preview']) )
+       <?php if (isset($_POST['preview'])|| isset($_POST['make_PDF']) )
 {
        ?>
 <p><?php echo $_POST['limitations']?></p>
@@ -313,7 +313,7 @@
        <dt><input type="checkbox" name="checkb_sublease_disallowed" <?php echo 
$disabled; if(isset($_POST['checkb_sublease_disallowed']) || 
isset($_POST['checkb_sublease_disallowed_hidden'])) {echo 
'checked="checked"';}?>  /></dt>
        <dd>Framleie er ikke tillatt, med mindre det er skriftlig avtalt.</dd>
        <dt><input type="checkbox" name="checkb_sublease_allowed" <?php echo 
$disabled; if(isset($_POST['checkb_sublease_allowed']) || 
isset($_POST['checkb_sublease_allowed_hidden'])) {echo 'checked="checked"';}?>  
/></dt>
-       <dd>Framleie er tillatt til: <?php if (isset($_POST['preview']) )
+       <dd>Framleie er tillatt til: <?php if (isset($_POST['preview']) || 
isset($_POST['make_PDF']))
        {
                ?> <?php echo $_POST['subtenant']?> <input type="hidden" 
name="subtenant" value="<?php echo $_POST['subtenant']?>" /> <?php
        }
@@ -334,7 +334,7 @@
        <dt><input type="checkbox" name="checkb_animals_disallowed" <?php echo 
$disabled; if(isset($_POST['checkb_animals_disallowed']) || 
isset($_POST['checkb_animals_disallowed_hidden'])) {echo 
'checked="checked"';}?>  /></dt>
        <dd>Dyrehold er ikke tillatt, med mindre det er skriftlig avtalt.</dd>
        <dt><input type="checkbox" name="checkb_animals_allowed" <?php echo 
$disabled; if(isset($_POST['checkb_animals_allowed']) || 
isset($_POST['checkb_animals_allowed_hidden'])) {echo 'checked="checked"';}?>  
/></dt>
-       <dd>Dyrehold er tillatt, ved at leier kan ha: <?php if 
(isset($_POST['preview']) )
+       <dd>Dyrehold er tillatt, ved at leier kan ha: <?php if 
(isset($_POST['preview']) || isset($_POST['make_PDF']))
        {
                ?> <?php echo $_POST['animals']?> <input type="hidden" 
name="animals" value="<?php echo $_POST['animals']?>" /> <?php
        }
@@ -457,11 +457,29 @@
                </td>
        </tr>
 </table>
-<?php if (isset($_POST['preview']) ){ ?>
+
+<?php if (isset($_POST['preview'])  ){ 
+$HtmlCode= ob_get_contents();
+ob_end_flush();
+
+$_SESSION['contract_html'] = $HtmlCode;
+       
+       ?>
 <input type="submit" value="Rediger" name="edit"> 
-<input type="submit" value="Lagre som PDF" name="make_PDF"> 
-<?php }else{?>
+</form>
 
-<input type="submit" value="Forhåndsvis" name="preview"> 
+<form action="<?php echo(html_entity_decode(self::link(array('menuaction' => 
'rental.uimakepdf.makePDF', 'id' => $value['id'], 'initial_load' => 
'no'))));?>" method="post">
+<input type="submit" value="Lagre som PDF" name="make_PDF" /> 
+
+</form>
+<?php
+
+
+}else{?>
+
+<input type="submit" value="Forhåndsvis" name="preview"> </form>
 <?php }?>
-</form>
+
+</div>
+
+




reply via email to

[Prev in Thread] Current Thread [Next in Thread]