├── package └── openvoucher │ ├── DEBIAN │ ├── postinst │ ├── preinst │ ├── conffiles │ └── control │ └── tmp │ └── ovsrc.tar.gz ├── src ├── classes │ ├── .htaccess │ ├── fpdf │ │ ├── font │ │ │ ├── courier.php │ │ │ ├── courierb.php │ │ │ ├── courieri.php │ │ │ ├── courierbi.php │ │ │ ├── zapfdingbats.php │ │ │ ├── symbol.php │ │ │ ├── times.php │ │ │ ├── timesi.php │ │ │ ├── helvetica.php │ │ │ ├── timesb.php │ │ │ ├── helveticab.php │ │ │ ├── timesbi.php │ │ │ ├── helveticai.php │ │ │ └── helveticabi.php │ │ └── fpdf.php │ ├── versionmanager.php │ ├── systemmanager.php │ ├── printvoucher.php │ ├── usermanager.php │ ├── gui.php │ ├── adminauth.php │ └── vouchermanager.php ├── includes │ ├── .htaccess │ ├── config.php │ └── header.php ├── .htaccess ├── localscripts │ ├── .htaccess │ └── refresh_permissions.php ├── admin │ ├── logout.php │ ├── dropvoucher.php │ ├── printvouchers.php │ ├── dropdevice.php │ ├── menu.php │ ├── index.php │ ├── functions.js │ ├── about.php │ ├── users.php │ ├── api.php │ ├── sysconfig.php │ └── addvoucher.php ├── graphics │ └── logo-small.png ├── index.php ├── style │ └── style.css └── landing │ ├── index.php │ ├── auth.php │ └── drop.php ├── graphics ├── logo.xcf ├── logo-medium.png ├── logo-small.png └── logo-small_white-bg.png ├── cronjobs └── cronjobs.txt ├── .gitattributes ├── release_notes.txt ├── database ├── upgrade_0.4.3-1.0.0.sql └── tables.sql ├── readme.txt ├── install_upgrade.txt └── .gitignore /package/openvoucher/DEBIAN/postinst: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | -------------------------------------------------------------------------------- /package/openvoucher/DEBIAN/preinst: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | -------------------------------------------------------------------------------- /src/classes/.htaccess: -------------------------------------------------------------------------------- 1 | order allow,deny 2 | deny from all 3 | -------------------------------------------------------------------------------- /src/includes/.htaccess: -------------------------------------------------------------------------------- 1 | order allow,deny 2 | deny from all 3 | -------------------------------------------------------------------------------- /src/.htaccess: -------------------------------------------------------------------------------- 1 | Options -Indexes 2 | ErrorDocument 404 /index.php 3 | -------------------------------------------------------------------------------- /src/localscripts/.htaccess: -------------------------------------------------------------------------------- 1 | order allow,deny 2 | deny from all 3 | -------------------------------------------------------------------------------- /package/openvoucher/DEBIAN/conffiles: -------------------------------------------------------------------------------- 1 | /var/www/includes/config.php 2 | -------------------------------------------------------------------------------- /graphics/logo.xcf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/litzinetz-de/OpenVoucher/HEAD/graphics/logo.xcf -------------------------------------------------------------------------------- /graphics/logo-medium.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/litzinetz-de/OpenVoucher/HEAD/graphics/logo-medium.png -------------------------------------------------------------------------------- /graphics/logo-small.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/litzinetz-de/OpenVoucher/HEAD/graphics/logo-small.png -------------------------------------------------------------------------------- /src/admin/logout.php: -------------------------------------------------------------------------------- 1 | Logout(); 5 | ?> -------------------------------------------------------------------------------- /src/graphics/logo-small.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/litzinetz-de/OpenVoucher/HEAD/src/graphics/logo-small.png -------------------------------------------------------------------------------- /graphics/logo-small_white-bg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/litzinetz-de/OpenVoucher/HEAD/graphics/logo-small_white-bg.png -------------------------------------------------------------------------------- /package/openvoucher/tmp/ovsrc.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/litzinetz-de/OpenVoucher/HEAD/package/openvoucher/tmp/ovsrc.tar.gz -------------------------------------------------------------------------------- /src/classes/fpdf/font/courier.php: -------------------------------------------------------------------------------- 1 | 9 | -------------------------------------------------------------------------------- /src/classes/fpdf/font/courierb.php: -------------------------------------------------------------------------------- 1 | 9 | -------------------------------------------------------------------------------- /src/classes/fpdf/font/courieri.php: -------------------------------------------------------------------------------- 1 | 9 | -------------------------------------------------------------------------------- /src/classes/fpdf/font/courierbi.php: -------------------------------------------------------------------------------- 1 | 9 | -------------------------------------------------------------------------------- /cronjobs/cronjobs.txt: -------------------------------------------------------------------------------- 1 | # Add this to the crontab of the user running apache (usually www-data on debian). 2 | # You might have to modify the paths 3 | # Do NOT run this cronjob by root! 4 | */5 * * * * php /var/www/localscripts/refresh_permissions.php 5 | -------------------------------------------------------------------------------- /src/localscripts/refresh_permissions.php: -------------------------------------------------------------------------------- 1 | DropOldVouchers(); 8 | ?> 9 | -------------------------------------------------------------------------------- /package/openvoucher/DEBIAN/control: -------------------------------------------------------------------------------- 1 | Package: openvoucher 2 | Version: 0.4.2 3 | Section: misc 4 | Priority: extra 5 | Architecture: all 6 | Depends: apache2 php5 php5-mysql mysql-server 7 | Installed-Size: 250 8 | Maintainer: Daniel Litzbach 9 | Homepage: www.openvoucher.org 10 | Description: OpenVoucher - www.openvoucher.org -------------------------------------------------------------------------------- /src/index.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/admin/dropvoucher.php: -------------------------------------------------------------------------------- 1 | CheckPermission('drop_voucher')) 6 | { 7 | require('../classes/gui.php'); 8 | $agui = new admingui(); 9 | include('../includes/header.php'); 10 | include('menu.php'); 11 | echo '
You have no permission to drop vouchers.
'; 12 | die(); 13 | } 14 | 15 | require('../classes/vouchermanager.php'); 16 | $v = new vouchermanager(); 17 | $v->DropVoucher($_GET['vid'],true); 18 | header('Location: index.php'); 19 | 20 | ?> -------------------------------------------------------------------------------- /src/admin/printvouchers.php: -------------------------------------------------------------------------------- 1 | CheckPermission('view_voucher')) 7 | { 8 | include('../includes/header.php'); 9 | include('menu.php'); 10 | echo '
You have no permission to view (and therefore print) vouchers.
'; 11 | die(); 12 | } 13 | 14 | require('../classes/printvoucher.php'); 15 | if(!isset($_SESSION['print_voucher_list'])) { die('No voucher list given.'); } 16 | $pr = new printvoucher('small',$_SESSION['print_voucher_list']); 17 | ?> -------------------------------------------------------------------------------- /src/admin/dropdevice.php: -------------------------------------------------------------------------------- 1 | CheckPermission('drop_device')) 6 | { 7 | require('../classes/gui.php'); 8 | $agui = new admingui(); 9 | include('../includes/header.php'); 10 | include('menu.php'); 11 | echo '
You have no permission to drop devices.
'; 12 | die(); 13 | } 14 | 15 | require('../classes/vouchermanager.php'); 16 | $v = new vouchermanager(); 17 | $v->DropDevice($_GET['type'],$_GET['addr']); 18 | header('Location: index.php'); 19 | 20 | ?> -------------------------------------------------------------------------------- /src/admin/menu.php: -------------------------------------------------------------------------------- 1 |
Admin interface
3 |
4 |
'; 12 | ?> -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | *.sln merge=union 7 | *.csproj merge=union 8 | *.vbproj merge=union 9 | *.fsproj merge=union 10 | *.dbproj merge=union 11 | 12 | # Standard to msysgit 13 | *.doc diff=astextplain 14 | *.DOC diff=astextplain 15 | *.docx diff=astextplain 16 | *.DOCX diff=astextplain 17 | *.dot diff=astextplain 18 | *.DOT diff=astextplain 19 | *.pdf diff=astextplain 20 | *.PDF diff=astextplain 21 | *.rtf diff=astextplain 22 | *.RTF diff=astextplain 23 | -------------------------------------------------------------------------------- /src/admin/index.php: -------------------------------------------------------------------------------- 1 | Active vouchers:
'; 15 | 16 | // List all vouchers 17 | if($a->CheckPermission('view_voucher')) 18 | { 19 | $agui->ListVouchers($v->GetVoucherList()); 20 | } else { 21 | echo '
You are now allowed to view vouchers.
'; 22 | } 23 | 24 | ?> 25 | 26 | -------------------------------------------------------------------------------- /src/includes/config.php: -------------------------------------------------------------------------------- 1 | 20 | -------------------------------------------------------------------------------- /src/classes/versionmanager.php: -------------------------------------------------------------------------------- 1 | NewestVersion())); 22 | $current=explode('.',trim(CURRENTVER)); 23 | 24 | if($newest[0]>$current[0]) // Major 25 | { 26 | return true; 27 | } elseif($newest[1]>$current[1]) // Minor 28 | { 29 | return true; 30 | } elseif($newest[2]>$current[2]) // Revision 31 | { 32 | return true; 33 | } else { 34 | return false; 35 | } 36 | } 37 | } 38 | ?> 39 | -------------------------------------------------------------------------------- /release_notes.txt: -------------------------------------------------------------------------------- 1 | Release notes for version 1.0.0 2 | 3 | Minimum required version when upgrading: 0.4.3 4 | 5 | Bugfixes 6 | ======== 7 | 8 | * Disabled caching for the landing page - this might lead to issues after authenticating 9 | * Reimplemented MySQL connection - mysql_connect and its' little helpers are deprecated. We're using mysqli now. See http://php.net/manual/en/function.mysql-connect.php for details 10 | 11 | Features 12 | ======== 13 | 14 | + Vouchers can now have a dynamic expiration time, based on the timestamp at the first usage 15 | + Dropping devices by the end user can now be disabled 16 | + A new config section "Change and enforce default values" is now available. It can be used for configuring various default values. Admins are optionally able to enforce each of these values, users that have the permission to issue vouchers are then bound to these default values and cannot change them anymore 17 | -------------------------------------------------------------------------------- /database/upgrade_0.4.3-1.0.0.sql: -------------------------------------------------------------------------------- 1 | USE openvoucher; 2 | ALTER TABLE vouchers ADD COLUMN valid_for INTEGER DEFAULT 0; 3 | INSERT INTO settings (setting,s_value) VALUES ('default_device-qty','3'); 4 | INSERT INTO settings (setting,s_value) VALUES ('default_voucher-qty','10'); 5 | INSERT INTO settings (setting,s_value) VALUES ('force_device-qty',''); 6 | INSERT INTO settings (setting,s_value) VALUES ('force_voucher-qty',''); 7 | 8 | INSERT INTO settings (setting,s_value) VALUES ('default_exp_d','0'); 9 | INSERT INTO settings (setting,s_value) VALUES ('default_exp_h','4'); 10 | INSERT INTO settings (setting,s_value) VALUES ('default_exp_m','0'); 11 | INSERT INTO settings (setting,s_value) VALUES ('force_exp',''); 12 | INSERT INTO settings (setting,s_value) VALUES ('default_start_exp','creation'); 13 | INSERT INTO settings (setting,s_value) VALUES ('force_start_exp',''); 14 | 15 | INSERT INTO settings (setting,s_value) VALUES ('deny_user_drop_device',''); -------------------------------------------------------------------------------- /readme.txt: -------------------------------------------------------------------------------- 1 | OpenVoucher is an open source voucher management / hotspot system for authenticating guests in your wifi or cable network. It is designed to be easy to use for anyone who wants to issue vouchers. 2 | 3 | For further information and installation how to's, see the project's homepage: 4 | 5 | http://openvoucher.litzinetz.de/ 6 | 7 | This program is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program. If not, see http://www.gnu.org/licenses/ 19 | -------------------------------------------------------------------------------- /src/includes/header.php: -------------------------------------------------------------------------------- 1 | GetSetting('logo'); 11 | if(file_exists('../graphics/'.$logo) && !is_dir('../graphics/'.$logo)) 12 | { 13 | $img_inc='../graphics/'.$logo; 14 | } else { 15 | $img_inc='../graphics/logo-small.png'; 16 | } 17 | ?> 18 | 19 | 20 | 21 | 22 | OpenVoucher 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 33 | 34 | 35 | 36 | 37 | 38 |
 
31 |
OpenVoucher
32 |
 
39 |
-------------------------------------------------------------------------------- /src/admin/functions.js: -------------------------------------------------------------------------------- 1 | function AddVoucherToggleExp() 2 | { 3 | if(document.voucherform.start_expire.value=="now") 4 | { 5 | document.voucherform.d.disabled=false; 6 | document.voucherform.h.disabled=false; 7 | document.voucherform.m.disabled=false; 8 | document.voucherform.e_d.disabled=true; 9 | document.voucherform.e_h.disabled=true; 10 | document.voucherform.e_m.disabled=true; 11 | 12 | document.voucherform.d.className="formstyle"; 13 | document.voucherform.h.className="formstyle"; 14 | document.voucherform.m.className="formstyle"; 15 | document.voucherform.e_d.className="roinput"; 16 | document.voucherform.e_h.className="roinput"; 17 | document.voucherform.e_m.className="roinput"; 18 | } else { 19 | document.voucherform.d.disabled=true; 20 | document.voucherform.h.disabled=true; 21 | document.voucherform.m.disabled=true; 22 | document.voucherform.e_d.disabled=false; 23 | document.voucherform.e_h.disabled=false; 24 | document.voucherform.e_m.disabled=false; 25 | 26 | document.voucherform.d.className="roinput"; 27 | document.voucherform.h.className="roinput"; 28 | document.voucherform.m.className="roinput"; 29 | document.voucherform.e_d.className="formstyle"; 30 | document.voucherform.e_h.className="formstyle"; 31 | document.voucherform.e_m.className="formstyle"; 32 | } 33 | } -------------------------------------------------------------------------------- /src/style/style.css: -------------------------------------------------------------------------------- 1 | body { 2 | color: #000000; 3 | background-color: #edf7ff; 4 | font: 13px/20px Arial,Helvetica,sans-serif; 5 | /*background-color: #F7F7F7;*/ 6 | } 7 | td { 8 | font: 13px/20px Arial,Helvetica,sans-serif; 9 | } 10 | a 11 | { 12 | color: #339ABB; 13 | } 14 | a, a:hover { 15 | text-decoration: none; 16 | } 17 | .header { 18 | font-size: 60; 19 | color: #6E6E6E; 20 | } 21 | .big { 22 | font-size: 40; 23 | } 24 | .middle { 25 | font-size: 30; 26 | } 27 | .small { 28 | font-size: 20; 29 | } 30 | .disabled { 31 | color: #4F3063; 32 | } 33 | .tableseperator 34 | { 35 | background-color: #c0c0c0; 36 | font-size: 1; 37 | } 38 | .lightbg 39 | { 40 | /*background-color: #F7F7F7;*/ 41 | background-color: #d7edff; 42 | } 43 | .darkbg 44 | { 45 | /*background-color: #e0e0e0;*/ 46 | background-color: #bde2ff; 47 | } 48 | .roinput 49 | { 50 | background-color: #c0c0c0; 51 | border: 1px solid #285b84; 52 | } 53 | .posselect 54 | { 55 | width: 100%; 56 | } 57 | .posinput 58 | { 59 | width: 100%; 60 | border: 1; 61 | } 62 | tr.tableheader 63 | { 64 | /*background-color: #c0c0c0;*/ 65 | background-color: #285b84; 66 | color: #ffffff; 67 | } 68 | .formstyle 69 | { 70 | background-color: #e5f1ff; 71 | border: 1px solid #285b84; 72 | } 73 | td.smalltd 74 | { 75 | font: 10px Arial,Helvetica,sans-serif; 76 | } -------------------------------------------------------------------------------- /src/admin/about.php: -------------------------------------------------------------------------------- 1 | Version '.$vers->GetCurrentVersion().'

13 | Copyright (C) '.$vers->GetReleaseYear().' Daniel Litzbach (www.litzinetz.de) and others

14 | 15 | This program is free software: you can redistribute it and/or modify 16 | it under the terms of the GNU General Public License as published by 17 | the Free Software Foundation, either version 3 of the License, or 18 | (at your option) any later version.

19 | 20 | This program is distributed in the hope that it will be useful, 21 | but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23 | GNU General Public License for more details.

24 | 25 | You should have received a copy of the GNU General Public License 26 | along with this program. If not, see http://www.gnu.org/licenses/. 27 |

28 | The OpenVoucher logo is based on the work by RRZEicons.'; 29 | ?> 30 | 31 | -------------------------------------------------------------------------------- /src/landing/index.php: -------------------------------------------------------------------------------- 1 | ClientAuthenticated(); 11 | 12 | $s = new systemmanager(); 13 | 14 | require('../includes/header.php'); // Must be included after creating instance of systemmanager 15 | 16 | if($clientdata!='noauth') 17 | { 18 | echo 'You are online and can now browse the internet.

19 | Your voucher ID is: '.$clientdata[2].'
'; 20 | 21 | $vinfo=$v->GetVoucherInfo($clientdata[2]); 22 | 23 | echo 'Your voucher is valid until '.date('Y-m-d H:i',$vinfo['valid_until']).' and you can register '.$vinfo['remain'].' more device(s) with this voucher.'; 24 | 25 | } else { 26 | echo $s->GetSetting('pre-form-text').'

27 |
28 | Voucher code: '; 29 | 30 | if($s->GetSetting('use_verification')=='y') 31 | { 32 | echo '
Verification key: '; 33 | } 34 | 35 | echo '

36 | 37 |


'.$s->GetSetting('post-form-text'); 38 | } 39 | ?> 40 | 41 | 42 | -------------------------------------------------------------------------------- /install_upgrade.txt: -------------------------------------------------------------------------------- 1 | Fresh installation 2 | ================== 3 | 4 | If you are going to setup a fresh installation of OpenVoucher, check the following link for installation instructions: 5 | 6 | http://openvoucher.litzinetz.de/documentation/installation/installation-from-source/ 7 | 8 | Upgrading a running installation 9 | ================================ 10 | 11 | If you're upgrading from a previous version, please follow these instructions: 12 | 13 | !!! When upgrading, you MUST have at least version 0.4.3 installed. If not, you should do a full reinstallation of OpenVoucher. You can export your MySQL database before the reinstallation and import it to the new database schema, to keep your data 14 | 15 | ---- 16 | 17 | * Copy the archive to your server and extract it 18 | 19 | * Change to the www directory of your webserver. On Debian systems, this is usually /var/www or /var/www/html 20 | 21 | * Copy the file includes/config.php to a safe place, e.g. /root/ 22 | 23 | * While still in the www directory, delete all contents of this directory (rm -rf *) 24 | 25 | * Copy the contents of the src/ directory from the archive into your www directory (please don't forget the .htaccess file, it is a hidden file!) 26 | 27 | * Copy the file config.php, which you have just saved, back to it's original location to restore your config settings 28 | 29 | * Make sure all the files and directorys inside your www directory are owned by the user running the webserver (e.g. chown -R www-data:www-data /var/www/) 30 | 31 | * Change to the database/ directory from the archive 32 | 33 | * Perform a database upgrade using the following command: mysql -u root -p < upgrade_0.4.3-1.0.0.sql (you will be asked for your mysql root password) 34 | 35 | You're done! 36 | -------------------------------------------------------------------------------- /src/landing/auth.php: -------------------------------------------------------------------------------- 1 | GetAuthMethod(); 9 | 10 | if($authtype=='mac-only') 11 | { 12 | // MAC 13 | $mac=$v->GetClientMAC(); 14 | if($mac!='') 15 | { 16 | $res=$v->AuthDevice($_POST['vid'],$_POST['verification_key'],'mac',$mac); 17 | if($res!='ok') 18 | { 19 | $auth_error=$res; 20 | } 21 | } else { 22 | $auth_error='no-mac'; 23 | } 24 | } elseif($authtype=='mac-ipv4') 25 | { 26 | // TODO MAC and IP4v fallback 27 | } elseif($authtype=='ipv4-only') 28 | { 29 | // IPv4 only 30 | $res=$v->AuthDevice($_POST['vid'],$_POST['verification_key'],'ipv4',$_SERVER['REMOTE_ADDR']); 31 | if($res!='ok') 32 | { 33 | $auth_error=$res; 34 | } 35 | } else { 36 | $auth_error='no-auth-method'; 37 | } 38 | 39 | if($auth_error!='') 40 | { 41 | include('../includes/header.php'); 42 | 43 | echo 'There has been a Problem authenticating your device.

'; 44 | 45 | if($auth_error=='no-mac') { echo 'I wasn\'t able to read your device\'n network address. Please contact an administrator.'; } 46 | if($auth_error=='no-auth-method') { echo 'I wasn\'t able to read the authentication method from the config. Please contact an administrator.'; } 47 | if($auth_error=='not-found-exceeded') { echo 'The voucher ID you have entered was not found, or the voucher has expired. Please check the voucher numer or request a new one.'; } 48 | if($auth_error=='maxnumber-reached') 49 | { 50 | echo 'You are not allowed to use more devices with this voucher.'; 51 | 52 | if($s->GetSetting('deny_drop_devices')!='y') 53 | { 54 | echo 'You can drop the internet access for a device that you don\'t need 55 | anymore, then try again.'; 56 | } 57 | } 58 | if($auth_error=='db-error') { echo 'We have a database error. Please contact an administrator.'; } 59 | if($auth_error=='verification-failed') { echo 'The verification of your voucher failed. Please check your verification key.'; } 60 | } else { 61 | header('Location: index.php'); 62 | } 63 | ?> -------------------------------------------------------------------------------- /src/classes/systemmanager.php: -------------------------------------------------------------------------------- 1 | defaults['vouchertext1']='Please enter the code'; 14 | $this->defaults['vouchertext2']='to get internet access'; 15 | $this->defaults['pre-form-text']='Please add your voucher code in the form below to get internet access.'; 16 | $this->defaults['post-form-text']='Feel free to contact an administrator if you have any problems.'; 17 | $this->defaults['use_verification']='n'; 18 | 19 | //$this->mysqlconn=mysql_connect(MYSQL_HOST,MYSQL_USER,MYSQL_PWD); 20 | //mysql_select_db(MYSQL_DB,$this->mysqlconn); 21 | $this->mysqlconn=new mysqli(MYSQL_HOST,MYSQL_USER,MYSQL_PWD,MYSQL_DB); 22 | } 23 | 24 | public function GetSetting($setting) 25 | { 26 | //$res=mysql_query('SELECT s_value FROM settings WHERE setting="'.$setting.'"',$this->mysqlconn); 27 | $qry='SELECT s_value FROM settings WHERE setting="'.$this->mysqlconn->real_escape_string($setting).'"'; 28 | $res=$this->mysqlconn->query($qry); 29 | //$row=mysql_fetch_array($res); 30 | $row=$res->fetch_assoc(); 31 | $return_value=$row['s_value']; 32 | 33 | if($return_value=='') 34 | { 35 | return $this->defaults[$setting]; 36 | } else { 37 | return $return_value; 38 | } 39 | } 40 | 41 | public function SetSetting($setting,$value) 42 | { 43 | //$res=mysql_query('SELECT COUNT(*) AS cnt FROM settings WHERE setting="'.$setting.'"',$this->mysqlconn); 44 | $qry='SELECT COUNT(*) AS cnt FROM settings WHERE setting="'.$this->mysqlconn->real_escape_string($setting).'"'; 45 | $res=$this->mysqlconn->query($qry); 46 | //$row=mysql_fetch_array($res); 47 | $row=$res->fetch_assoc(); 48 | if($row['cnt']>0) 49 | { 50 | $qry='UPDATE settings SET s_value="'.$this->mysqlconn->real_escape_string($value).'" WHERE setting="'.$this->mysqlconn->real_escape_string($setting).'"'; 51 | } else { 52 | $qry='INSERT INTO settings (setting,s_value) VALUES ("'.$this->mysqlconn->real_escape_string($setting).'","'.$this->mysqlconn->real_escape_string($value).'")'; 53 | } 54 | //mysql_query($query,$this->mysqlconn); 55 | $this->mysqlconn->query($qry); 56 | } 57 | } 58 | } 59 | ?> -------------------------------------------------------------------------------- /src/classes/printvoucher.php: -------------------------------------------------------------------------------- 1 | Image('../graphics/logo-small.png',10,6,15); 12 | // Arial bold 15 13 | $this->SetFont('Arial','B',15); 14 | // Move to the right 15 | $this->Cell(80); 16 | // Title 17 | $this->Cell(30,10,'OpenVoucher',0,0,'C'); 18 | $this->Image('../graphics/logo-small.png',180,6,15); 19 | // Line 20 | $this->Line(0,25,220,25); 21 | } 22 | 23 | // Page footer 24 | function Footer() 25 | { 26 | // Position at 1.5 cm from bottom 27 | $this->SetY(-15); 28 | // Arial italic 8 29 | $this->SetFont('Arial','I',8); 30 | // Page number 31 | $this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C'); 32 | } 33 | } 34 | 35 | class printvoucher 36 | { 37 | private $pdf; 38 | private $vouchertype; 39 | private $voucherlist; 40 | private $s; 41 | 42 | // vouchertype: small (many vouchers per page) or big (one voucher per page) 43 | // voucherlist: array of voucher IDs to print 44 | function __construct($vouchertype,$voucherlist) 45 | { 46 | $this->s = new systemmanager(); 47 | 48 | $this->pdf=new PDF(); 49 | $this->vouchertype=$vouchertype; 50 | $this->voucherlist=$voucherlist; 51 | 52 | $this->pdf = new PDF(); 53 | $this->pdf->AliasNbPages(); 54 | $this->pdf->AddPage(); 55 | $this->pdf->SetAutoPageBreak(false); 56 | $this->pdf->SetFont('Arial','',8); 57 | 58 | if($vouchertype=='small') // Small vouchers 59 | { 60 | $this->pdf->SetXY(4,30); 61 | $j=1; // count cols 62 | $k=1; // count rows 63 | for($i=0;$ipdf->SetXY(4,$this->pdf->GetY()+20); 68 | $j=1; 69 | $k++; 70 | } 71 | if($k==12) 72 | { 73 | $this->pdf->AddPage(); 74 | $this->pdf->SetXY(4,30); 75 | $k=1; 76 | } 77 | $this->pdf->Cell(40,20,'',1,0); 78 | $this->pdf->SetX($this->pdf->GetX()-40); 79 | $this->pdf->Cell(40,5,'Voucher ID:',0,2,'C'); 80 | $this->pdf->Cell(40,5,$voucherlist[$i],0,2,'C'); 81 | $this->pdf->Cell(40,5,$this->s->GetSetting('vouchertext1'),0,2,'C'); 82 | $this->pdf->Cell(40,5,$this->s->GetSetting('vouchertext2'),0,0,'C'); 83 | $this->pdf->SetXY($this->pdf->GetX(),$this->pdf->GetY()-15); 84 | $j++; 85 | } 86 | } 87 | 88 | $this->pdf->Output(); 89 | } 90 | } 91 | ?> -------------------------------------------------------------------------------- /src/landing/drop.php: -------------------------------------------------------------------------------- 1 | GetAuthMethod(); 10 | 11 | require('../includes/header.php'); 12 | 13 | if($s->GetSetting('deny_drop_devices')=='y') 14 | { 15 | die('Sorry, dropping devices has been disabled by the admin.'); 16 | } 17 | 18 | if($_GET['do']=='') 19 | { 20 | echo 'To drop a device, please enter your voucher code again:

21 |
22 | Voucher code: '; 23 | 24 | if($s->GetSetting('use_verification')=='y') 25 | { 26 | echo '
Verification key: '; 27 | } 28 | 29 | echo '

30 | '; 31 | } 32 | 33 | if($_GET['do']=='lst-devices') 34 | { 35 | if($s->GetSetting('use_verification')=='y') 36 | { 37 | if(!$v->VerifyVoucherKey($_POST['vid'],$_POST['verification_key'])) 38 | { 39 | echo 'The verification key is invalid. Please go back and try again.'; 40 | die(); 41 | } 42 | } 43 | 44 | $voucher_info=$v->GetVoucherInfo($_POST['vid']); 45 | $devices=$v->GetDeviceList($_POST['vid']); 46 | 47 | echo 'Device count: '.$voucher_info['dev_count'].' ('.$voucher_info['remain'].' left)
48 | Valid until: '.date('Y-m-d H:i',$voucher_info['valid_until']).'

Choose one of these devices to drop:
'; 49 | 50 | foreach($devices as $device) 51 | { 52 | echo ''; 53 | } 54 | } 55 | 56 | if($_GET['do']=='drop') 57 | { 58 | if($s->GetSetting('use_verification')=='y') 59 | { 60 | if(!$v->VerifyVoucherKey($_GET['vid'],$_GET['verification_key'])) 61 | { 62 | echo 'The verification key is invalid. Please go back and try again.'; 63 | die(); 64 | } 65 | } 66 | 67 | if(!isset($_GET['device'])) 68 | { 69 | echo 'Couldn\'t get device.'; 70 | die(); 71 | } 72 | $v->DropDevice($_GET['type'],$_GET['device']); 73 | echo 'The device has been dropped. You can now go back and login with your voucher.'; 74 | } 75 | 76 | ?> 77 | 78 | 79 | -------------------------------------------------------------------------------- /database/tables.sql: -------------------------------------------------------------------------------- 1 | CREATE DATABASE IF NOT EXISTS openvoucher; 2 | USE openvoucher; 3 | 4 | DROP TABLE IF EXISTS `devices`; 5 | CREATE TABLE IF NOT EXISTS `devices` ( 6 | `type` varchar(10) NOT NULL, 7 | `addr` varchar(255) NOT NULL, 8 | `voucher_id` varchar(255) NOT NULL, 9 | PRIMARY KEY (`type`,`addr`) 10 | ) ENGINE=InnoDB DEFAULT CHARSET=latin1; 11 | 12 | -- -------------------------------------------------------- 13 | 14 | DROP TABLE IF EXISTS `permissions`; 15 | CREATE TABLE IF NOT EXISTS `permissions` ( 16 | `username` varchar(255) NOT NULL, 17 | `permission` varchar(255) NOT NULL, 18 | PRIMARY KEY (`username`,`permission`) 19 | ) ENGINE=InnoDB DEFAULT CHARSET=latin1; 20 | 21 | -- -------------------------------------------------------- 22 | 23 | DROP TABLE IF EXISTS `users`; 24 | CREATE TABLE IF NOT EXISTS `users` ( 25 | `username` varchar(255) NOT NULL, 26 | `pwd` varchar(255) NOT NULL, 27 | `type` varchar(10) NOT NULL, 28 | PRIMARY KEY (`username`) 29 | ) ENGINE=InnoDB DEFAULT CHARSET=latin1; 30 | 31 | -- -------------------------------------------------------- 32 | 33 | DROP TABLE IF EXISTS `vouchers`; 34 | CREATE TABLE IF NOT EXISTS `vouchers` ( 35 | `voucher_id` varchar(255) NOT NULL, 36 | `dev_count` int(11) NOT NULL, 37 | `valid_until` int(11) NOT NULL, 38 | `verification_key` varchar(255), 39 | `comment` varchar(255) NOT NULL, 40 | `valid_for` INTEGER DEFAULT 0, 41 | PRIMARY KEY (`voucher_id`) 42 | ) ENGINE=InnoDB DEFAULT CHARSET=latin1; 43 | 44 | -- --------------------------------------------------------- 45 | 46 | DROP TABLE IF EXISTS `settings`; 47 | CREATE TABLE settings ( 48 | setting VARCHAR(255) NOT NULL PRIMARY KEY, 49 | s_value VARCHAR(255) NOT NULL 50 | ) ENGINE=InnoDB DEFAULT CHARSET=latin1; 51 | 52 | -- add an admin user 53 | INSERT INTO users (username,pwd) VALUES ('admin',SHA1('admin')); 54 | INSERT INTO permissions (username,permission) VALUES ('admin','all'); 55 | 56 | -- default config 57 | INSERT INTO settings (setting,s_value) VALUES ('vouchertext1','Please enter the code'); 58 | INSERT INTO settings (setting,s_value) VALUES ('vouchertext2','to get internet access'); 59 | INSERT INTO settings (setting,s_value) VALUES ('use_verification','n'); 60 | INSERT INTO settings (setting,s_value) VALUES ('default_device-qty','3'); 61 | INSERT INTO settings (setting,s_value) VALUES ('default_voucher-qty','10'); 62 | INSERT INTO settings (setting,s_value) VALUES ('force_device-qty',''); 63 | INSERT INTO settings (setting,s_value) VALUES ('force_voucher-qty',''); 64 | INSERT INTO settings (setting,s_value) VALUES ('default_exp_d','0'); 65 | INSERT INTO settings (setting,s_value) VALUES ('default_exp_h','4'); 66 | INSERT INTO settings (setting,s_value) VALUES ('default_exp_m','0'); 67 | INSERT INTO settings (setting,s_value) VALUES ('force_exp',''); 68 | INSERT INTO settings (setting,s_value) VALUES ('default_start_exp','creation'); 69 | INSERT INTO settings (setting,s_value) VALUES ('force_start_exp',''); 70 | INSERT INTO settings (setting,s_value) VALUES ('deny_user_drop_device',''); 71 | -------------------------------------------------------------------------------- /src/classes/fpdf/font/zapfdingbats.php: -------------------------------------------------------------------------------- 1 | 0,chr(1)=>0,chr(2)=>0,chr(3)=>0,chr(4)=>0,chr(5)=>0,chr(6)=>0,chr(7)=>0,chr(8)=>0,chr(9)=>0,chr(10)=>0,chr(11)=>0,chr(12)=>0,chr(13)=>0,chr(14)=>0,chr(15)=>0,chr(16)=>0,chr(17)=>0,chr(18)=>0,chr(19)=>0,chr(20)=>0,chr(21)=>0, 8 | chr(22)=>0,chr(23)=>0,chr(24)=>0,chr(25)=>0,chr(26)=>0,chr(27)=>0,chr(28)=>0,chr(29)=>0,chr(30)=>0,chr(31)=>0,' '=>278,'!'=>974,'"'=>961,'#'=>974,'$'=>980,'%'=>719,'&'=>789,'\''=>790,'('=>791,')'=>690,'*'=>960,'+'=>939, 9 | ','=>549,'-'=>855,'.'=>911,'/'=>933,'0'=>911,'1'=>945,'2'=>974,'3'=>755,'4'=>846,'5'=>762,'6'=>761,'7'=>571,'8'=>677,'9'=>763,':'=>760,';'=>759,'<'=>754,'='=>494,'>'=>552,'?'=>537,'@'=>577,'A'=>692, 10 | 'B'=>786,'C'=>788,'D'=>788,'E'=>790,'F'=>793,'G'=>794,'H'=>816,'I'=>823,'J'=>789,'K'=>841,'L'=>823,'M'=>833,'N'=>816,'O'=>831,'P'=>923,'Q'=>744,'R'=>723,'S'=>749,'T'=>790,'U'=>792,'V'=>695,'W'=>776, 11 | 'X'=>768,'Y'=>792,'Z'=>759,'['=>707,'\\'=>708,']'=>682,'^'=>701,'_'=>826,'`'=>815,'a'=>789,'b'=>789,'c'=>707,'d'=>687,'e'=>696,'f'=>689,'g'=>786,'h'=>787,'i'=>713,'j'=>791,'k'=>785,'l'=>791,'m'=>873, 12 | 'n'=>761,'o'=>762,'p'=>762,'q'=>759,'r'=>759,'s'=>892,'t'=>892,'u'=>788,'v'=>784,'w'=>438,'x'=>138,'y'=>277,'z'=>415,'{'=>392,'|'=>392,'}'=>668,'~'=>668,chr(127)=>0,chr(128)=>390,chr(129)=>390,chr(130)=>317,chr(131)=>317, 13 | chr(132)=>276,chr(133)=>276,chr(134)=>509,chr(135)=>509,chr(136)=>410,chr(137)=>410,chr(138)=>234,chr(139)=>234,chr(140)=>334,chr(141)=>334,chr(142)=>0,chr(143)=>0,chr(144)=>0,chr(145)=>0,chr(146)=>0,chr(147)=>0,chr(148)=>0,chr(149)=>0,chr(150)=>0,chr(151)=>0,chr(152)=>0,chr(153)=>0, 14 | chr(154)=>0,chr(155)=>0,chr(156)=>0,chr(157)=>0,chr(158)=>0,chr(159)=>0,chr(160)=>0,chr(161)=>732,chr(162)=>544,chr(163)=>544,chr(164)=>910,chr(165)=>667,chr(166)=>760,chr(167)=>760,chr(168)=>776,chr(169)=>595,chr(170)=>694,chr(171)=>626,chr(172)=>788,chr(173)=>788,chr(174)=>788,chr(175)=>788, 15 | chr(176)=>788,chr(177)=>788,chr(178)=>788,chr(179)=>788,chr(180)=>788,chr(181)=>788,chr(182)=>788,chr(183)=>788,chr(184)=>788,chr(185)=>788,chr(186)=>788,chr(187)=>788,chr(188)=>788,chr(189)=>788,chr(190)=>788,chr(191)=>788,chr(192)=>788,chr(193)=>788,chr(194)=>788,chr(195)=>788,chr(196)=>788,chr(197)=>788, 16 | chr(198)=>788,chr(199)=>788,chr(200)=>788,chr(201)=>788,chr(202)=>788,chr(203)=>788,chr(204)=>788,chr(205)=>788,chr(206)=>788,chr(207)=>788,chr(208)=>788,chr(209)=>788,chr(210)=>788,chr(211)=>788,chr(212)=>894,chr(213)=>838,chr(214)=>1016,chr(215)=>458,chr(216)=>748,chr(217)=>924,chr(218)=>748,chr(219)=>918, 17 | chr(220)=>927,chr(221)=>928,chr(222)=>928,chr(223)=>834,chr(224)=>873,chr(225)=>828,chr(226)=>924,chr(227)=>924,chr(228)=>917,chr(229)=>930,chr(230)=>931,chr(231)=>463,chr(232)=>883,chr(233)=>836,chr(234)=>836,chr(235)=>867,chr(236)=>867,chr(237)=>696,chr(238)=>696,chr(239)=>874,chr(240)=>0,chr(241)=>874, 18 | chr(242)=>760,chr(243)=>946,chr(244)=>771,chr(245)=>865,chr(246)=>771,chr(247)=>888,chr(248)=>967,chr(249)=>888,chr(250)=>831,chr(251)=>873,chr(252)=>927,chr(253)=>970,chr(254)=>918,chr(255)=>0); 19 | ?> 20 | -------------------------------------------------------------------------------- /src/classes/fpdf/font/symbol.php: -------------------------------------------------------------------------------- 1 | 250,chr(1)=>250,chr(2)=>250,chr(3)=>250,chr(4)=>250,chr(5)=>250,chr(6)=>250,chr(7)=>250,chr(8)=>250,chr(9)=>250,chr(10)=>250,chr(11)=>250,chr(12)=>250,chr(13)=>250,chr(14)=>250,chr(15)=>250,chr(16)=>250,chr(17)=>250,chr(18)=>250,chr(19)=>250,chr(20)=>250,chr(21)=>250, 8 | chr(22)=>250,chr(23)=>250,chr(24)=>250,chr(25)=>250,chr(26)=>250,chr(27)=>250,chr(28)=>250,chr(29)=>250,chr(30)=>250,chr(31)=>250,' '=>250,'!'=>333,'"'=>713,'#'=>500,'$'=>549,'%'=>833,'&'=>778,'\''=>439,'('=>333,')'=>333,'*'=>500,'+'=>549, 9 | ','=>250,'-'=>549,'.'=>250,'/'=>278,'0'=>500,'1'=>500,'2'=>500,'3'=>500,'4'=>500,'5'=>500,'6'=>500,'7'=>500,'8'=>500,'9'=>500,':'=>278,';'=>278,'<'=>549,'='=>549,'>'=>549,'?'=>444,'@'=>549,'A'=>722, 10 | 'B'=>667,'C'=>722,'D'=>612,'E'=>611,'F'=>763,'G'=>603,'H'=>722,'I'=>333,'J'=>631,'K'=>722,'L'=>686,'M'=>889,'N'=>722,'O'=>722,'P'=>768,'Q'=>741,'R'=>556,'S'=>592,'T'=>611,'U'=>690,'V'=>439,'W'=>768, 11 | 'X'=>645,'Y'=>795,'Z'=>611,'['=>333,'\\'=>863,']'=>333,'^'=>658,'_'=>500,'`'=>500,'a'=>631,'b'=>549,'c'=>549,'d'=>494,'e'=>439,'f'=>521,'g'=>411,'h'=>603,'i'=>329,'j'=>603,'k'=>549,'l'=>549,'m'=>576, 12 | 'n'=>521,'o'=>549,'p'=>549,'q'=>521,'r'=>549,'s'=>603,'t'=>439,'u'=>576,'v'=>713,'w'=>686,'x'=>493,'y'=>686,'z'=>494,'{'=>480,'|'=>200,'}'=>480,'~'=>549,chr(127)=>0,chr(128)=>0,chr(129)=>0,chr(130)=>0,chr(131)=>0, 13 | chr(132)=>0,chr(133)=>0,chr(134)=>0,chr(135)=>0,chr(136)=>0,chr(137)=>0,chr(138)=>0,chr(139)=>0,chr(140)=>0,chr(141)=>0,chr(142)=>0,chr(143)=>0,chr(144)=>0,chr(145)=>0,chr(146)=>0,chr(147)=>0,chr(148)=>0,chr(149)=>0,chr(150)=>0,chr(151)=>0,chr(152)=>0,chr(153)=>0, 14 | chr(154)=>0,chr(155)=>0,chr(156)=>0,chr(157)=>0,chr(158)=>0,chr(159)=>0,chr(160)=>750,chr(161)=>620,chr(162)=>247,chr(163)=>549,chr(164)=>167,chr(165)=>713,chr(166)=>500,chr(167)=>753,chr(168)=>753,chr(169)=>753,chr(170)=>753,chr(171)=>1042,chr(172)=>987,chr(173)=>603,chr(174)=>987,chr(175)=>603, 15 | chr(176)=>400,chr(177)=>549,chr(178)=>411,chr(179)=>549,chr(180)=>549,chr(181)=>713,chr(182)=>494,chr(183)=>460,chr(184)=>549,chr(185)=>549,chr(186)=>549,chr(187)=>549,chr(188)=>1000,chr(189)=>603,chr(190)=>1000,chr(191)=>658,chr(192)=>823,chr(193)=>686,chr(194)=>795,chr(195)=>987,chr(196)=>768,chr(197)=>768, 16 | chr(198)=>823,chr(199)=>768,chr(200)=>768,chr(201)=>713,chr(202)=>713,chr(203)=>713,chr(204)=>713,chr(205)=>713,chr(206)=>713,chr(207)=>713,chr(208)=>768,chr(209)=>713,chr(210)=>790,chr(211)=>790,chr(212)=>890,chr(213)=>823,chr(214)=>549,chr(215)=>250,chr(216)=>713,chr(217)=>603,chr(218)=>603,chr(219)=>1042, 17 | chr(220)=>987,chr(221)=>603,chr(222)=>987,chr(223)=>603,chr(224)=>494,chr(225)=>329,chr(226)=>790,chr(227)=>790,chr(228)=>786,chr(229)=>713,chr(230)=>384,chr(231)=>384,chr(232)=>384,chr(233)=>384,chr(234)=>384,chr(235)=>384,chr(236)=>494,chr(237)=>494,chr(238)=>494,chr(239)=>494,chr(240)=>0,chr(241)=>329, 18 | chr(242)=>274,chr(243)=>686,chr(244)=>686,chr(245)=>686,chr(246)=>384,chr(247)=>384,chr(248)=>384,chr(249)=>384,chr(250)=>384,chr(251)=>384,chr(252)=>494,chr(253)=>494,chr(254)=>494,chr(255)=>0); 19 | ?> 20 | -------------------------------------------------------------------------------- /src/classes/fpdf/font/times.php: -------------------------------------------------------------------------------- 1 | 250,chr(1)=>250,chr(2)=>250,chr(3)=>250,chr(4)=>250,chr(5)=>250,chr(6)=>250,chr(7)=>250,chr(8)=>250,chr(9)=>250,chr(10)=>250,chr(11)=>250,chr(12)=>250,chr(13)=>250,chr(14)=>250,chr(15)=>250,chr(16)=>250,chr(17)=>250,chr(18)=>250,chr(19)=>250,chr(20)=>250,chr(21)=>250, 8 | chr(22)=>250,chr(23)=>250,chr(24)=>250,chr(25)=>250,chr(26)=>250,chr(27)=>250,chr(28)=>250,chr(29)=>250,chr(30)=>250,chr(31)=>250,' '=>250,'!'=>333,'"'=>408,'#'=>500,'$'=>500,'%'=>833,'&'=>778,'\''=>180,'('=>333,')'=>333,'*'=>500,'+'=>564, 9 | ','=>250,'-'=>333,'.'=>250,'/'=>278,'0'=>500,'1'=>500,'2'=>500,'3'=>500,'4'=>500,'5'=>500,'6'=>500,'7'=>500,'8'=>500,'9'=>500,':'=>278,';'=>278,'<'=>564,'='=>564,'>'=>564,'?'=>444,'@'=>921,'A'=>722, 10 | 'B'=>667,'C'=>667,'D'=>722,'E'=>611,'F'=>556,'G'=>722,'H'=>722,'I'=>333,'J'=>389,'K'=>722,'L'=>611,'M'=>889,'N'=>722,'O'=>722,'P'=>556,'Q'=>722,'R'=>667,'S'=>556,'T'=>611,'U'=>722,'V'=>722,'W'=>944, 11 | 'X'=>722,'Y'=>722,'Z'=>611,'['=>333,'\\'=>278,']'=>333,'^'=>469,'_'=>500,'`'=>333,'a'=>444,'b'=>500,'c'=>444,'d'=>500,'e'=>444,'f'=>333,'g'=>500,'h'=>500,'i'=>278,'j'=>278,'k'=>500,'l'=>278,'m'=>778, 12 | 'n'=>500,'o'=>500,'p'=>500,'q'=>500,'r'=>333,'s'=>389,'t'=>278,'u'=>500,'v'=>500,'w'=>722,'x'=>500,'y'=>500,'z'=>444,'{'=>480,'|'=>200,'}'=>480,'~'=>541,chr(127)=>350,chr(128)=>500,chr(129)=>350,chr(130)=>333,chr(131)=>500, 13 | chr(132)=>444,chr(133)=>1000,chr(134)=>500,chr(135)=>500,chr(136)=>333,chr(137)=>1000,chr(138)=>556,chr(139)=>333,chr(140)=>889,chr(141)=>350,chr(142)=>611,chr(143)=>350,chr(144)=>350,chr(145)=>333,chr(146)=>333,chr(147)=>444,chr(148)=>444,chr(149)=>350,chr(150)=>500,chr(151)=>1000,chr(152)=>333,chr(153)=>980, 14 | chr(154)=>389,chr(155)=>333,chr(156)=>722,chr(157)=>350,chr(158)=>444,chr(159)=>722,chr(160)=>250,chr(161)=>333,chr(162)=>500,chr(163)=>500,chr(164)=>500,chr(165)=>500,chr(166)=>200,chr(167)=>500,chr(168)=>333,chr(169)=>760,chr(170)=>276,chr(171)=>500,chr(172)=>564,chr(173)=>333,chr(174)=>760,chr(175)=>333, 15 | chr(176)=>400,chr(177)=>564,chr(178)=>300,chr(179)=>300,chr(180)=>333,chr(181)=>500,chr(182)=>453,chr(183)=>250,chr(184)=>333,chr(185)=>300,chr(186)=>310,chr(187)=>500,chr(188)=>750,chr(189)=>750,chr(190)=>750,chr(191)=>444,chr(192)=>722,chr(193)=>722,chr(194)=>722,chr(195)=>722,chr(196)=>722,chr(197)=>722, 16 | chr(198)=>889,chr(199)=>667,chr(200)=>611,chr(201)=>611,chr(202)=>611,chr(203)=>611,chr(204)=>333,chr(205)=>333,chr(206)=>333,chr(207)=>333,chr(208)=>722,chr(209)=>722,chr(210)=>722,chr(211)=>722,chr(212)=>722,chr(213)=>722,chr(214)=>722,chr(215)=>564,chr(216)=>722,chr(217)=>722,chr(218)=>722,chr(219)=>722, 17 | chr(220)=>722,chr(221)=>722,chr(222)=>556,chr(223)=>500,chr(224)=>444,chr(225)=>444,chr(226)=>444,chr(227)=>444,chr(228)=>444,chr(229)=>444,chr(230)=>667,chr(231)=>444,chr(232)=>444,chr(233)=>444,chr(234)=>444,chr(235)=>444,chr(236)=>278,chr(237)=>278,chr(238)=>278,chr(239)=>278,chr(240)=>500,chr(241)=>500, 18 | chr(242)=>500,chr(243)=>500,chr(244)=>500,chr(245)=>500,chr(246)=>500,chr(247)=>564,chr(248)=>500,chr(249)=>500,chr(250)=>500,chr(251)=>500,chr(252)=>500,chr(253)=>500,chr(254)=>500,chr(255)=>500); 19 | ?> 20 | -------------------------------------------------------------------------------- /src/classes/fpdf/font/timesi.php: -------------------------------------------------------------------------------- 1 | 250,chr(1)=>250,chr(2)=>250,chr(3)=>250,chr(4)=>250,chr(5)=>250,chr(6)=>250,chr(7)=>250,chr(8)=>250,chr(9)=>250,chr(10)=>250,chr(11)=>250,chr(12)=>250,chr(13)=>250,chr(14)=>250,chr(15)=>250,chr(16)=>250,chr(17)=>250,chr(18)=>250,chr(19)=>250,chr(20)=>250,chr(21)=>250, 8 | chr(22)=>250,chr(23)=>250,chr(24)=>250,chr(25)=>250,chr(26)=>250,chr(27)=>250,chr(28)=>250,chr(29)=>250,chr(30)=>250,chr(31)=>250,' '=>250,'!'=>333,'"'=>420,'#'=>500,'$'=>500,'%'=>833,'&'=>778,'\''=>214,'('=>333,')'=>333,'*'=>500,'+'=>675, 9 | ','=>250,'-'=>333,'.'=>250,'/'=>278,'0'=>500,'1'=>500,'2'=>500,'3'=>500,'4'=>500,'5'=>500,'6'=>500,'7'=>500,'8'=>500,'9'=>500,':'=>333,';'=>333,'<'=>675,'='=>675,'>'=>675,'?'=>500,'@'=>920,'A'=>611, 10 | 'B'=>611,'C'=>667,'D'=>722,'E'=>611,'F'=>611,'G'=>722,'H'=>722,'I'=>333,'J'=>444,'K'=>667,'L'=>556,'M'=>833,'N'=>667,'O'=>722,'P'=>611,'Q'=>722,'R'=>611,'S'=>500,'T'=>556,'U'=>722,'V'=>611,'W'=>833, 11 | 'X'=>611,'Y'=>556,'Z'=>556,'['=>389,'\\'=>278,']'=>389,'^'=>422,'_'=>500,'`'=>333,'a'=>500,'b'=>500,'c'=>444,'d'=>500,'e'=>444,'f'=>278,'g'=>500,'h'=>500,'i'=>278,'j'=>278,'k'=>444,'l'=>278,'m'=>722, 12 | 'n'=>500,'o'=>500,'p'=>500,'q'=>500,'r'=>389,'s'=>389,'t'=>278,'u'=>500,'v'=>444,'w'=>667,'x'=>444,'y'=>444,'z'=>389,'{'=>400,'|'=>275,'}'=>400,'~'=>541,chr(127)=>350,chr(128)=>500,chr(129)=>350,chr(130)=>333,chr(131)=>500, 13 | chr(132)=>556,chr(133)=>889,chr(134)=>500,chr(135)=>500,chr(136)=>333,chr(137)=>1000,chr(138)=>500,chr(139)=>333,chr(140)=>944,chr(141)=>350,chr(142)=>556,chr(143)=>350,chr(144)=>350,chr(145)=>333,chr(146)=>333,chr(147)=>556,chr(148)=>556,chr(149)=>350,chr(150)=>500,chr(151)=>889,chr(152)=>333,chr(153)=>980, 14 | chr(154)=>389,chr(155)=>333,chr(156)=>667,chr(157)=>350,chr(158)=>389,chr(159)=>556,chr(160)=>250,chr(161)=>389,chr(162)=>500,chr(163)=>500,chr(164)=>500,chr(165)=>500,chr(166)=>275,chr(167)=>500,chr(168)=>333,chr(169)=>760,chr(170)=>276,chr(171)=>500,chr(172)=>675,chr(173)=>333,chr(174)=>760,chr(175)=>333, 15 | chr(176)=>400,chr(177)=>675,chr(178)=>300,chr(179)=>300,chr(180)=>333,chr(181)=>500,chr(182)=>523,chr(183)=>250,chr(184)=>333,chr(185)=>300,chr(186)=>310,chr(187)=>500,chr(188)=>750,chr(189)=>750,chr(190)=>750,chr(191)=>500,chr(192)=>611,chr(193)=>611,chr(194)=>611,chr(195)=>611,chr(196)=>611,chr(197)=>611, 16 | chr(198)=>889,chr(199)=>667,chr(200)=>611,chr(201)=>611,chr(202)=>611,chr(203)=>611,chr(204)=>333,chr(205)=>333,chr(206)=>333,chr(207)=>333,chr(208)=>722,chr(209)=>667,chr(210)=>722,chr(211)=>722,chr(212)=>722,chr(213)=>722,chr(214)=>722,chr(215)=>675,chr(216)=>722,chr(217)=>722,chr(218)=>722,chr(219)=>722, 17 | chr(220)=>722,chr(221)=>556,chr(222)=>611,chr(223)=>500,chr(224)=>500,chr(225)=>500,chr(226)=>500,chr(227)=>500,chr(228)=>500,chr(229)=>500,chr(230)=>667,chr(231)=>444,chr(232)=>444,chr(233)=>444,chr(234)=>444,chr(235)=>444,chr(236)=>278,chr(237)=>278,chr(238)=>278,chr(239)=>278,chr(240)=>500,chr(241)=>500, 18 | chr(242)=>500,chr(243)=>500,chr(244)=>500,chr(245)=>500,chr(246)=>500,chr(247)=>675,chr(248)=>500,chr(249)=>500,chr(250)=>500,chr(251)=>500,chr(252)=>500,chr(253)=>444,chr(254)=>500,chr(255)=>444); 19 | ?> 20 | -------------------------------------------------------------------------------- /src/classes/fpdf/font/helvetica.php: -------------------------------------------------------------------------------- 1 | 278,chr(1)=>278,chr(2)=>278,chr(3)=>278,chr(4)=>278,chr(5)=>278,chr(6)=>278,chr(7)=>278,chr(8)=>278,chr(9)=>278,chr(10)=>278,chr(11)=>278,chr(12)=>278,chr(13)=>278,chr(14)=>278,chr(15)=>278,chr(16)=>278,chr(17)=>278,chr(18)=>278,chr(19)=>278,chr(20)=>278,chr(21)=>278, 8 | chr(22)=>278,chr(23)=>278,chr(24)=>278,chr(25)=>278,chr(26)=>278,chr(27)=>278,chr(28)=>278,chr(29)=>278,chr(30)=>278,chr(31)=>278,' '=>278,'!'=>278,'"'=>355,'#'=>556,'$'=>556,'%'=>889,'&'=>667,'\''=>191,'('=>333,')'=>333,'*'=>389,'+'=>584, 9 | ','=>278,'-'=>333,'.'=>278,'/'=>278,'0'=>556,'1'=>556,'2'=>556,'3'=>556,'4'=>556,'5'=>556,'6'=>556,'7'=>556,'8'=>556,'9'=>556,':'=>278,';'=>278,'<'=>584,'='=>584,'>'=>584,'?'=>556,'@'=>1015,'A'=>667, 10 | 'B'=>667,'C'=>722,'D'=>722,'E'=>667,'F'=>611,'G'=>778,'H'=>722,'I'=>278,'J'=>500,'K'=>667,'L'=>556,'M'=>833,'N'=>722,'O'=>778,'P'=>667,'Q'=>778,'R'=>722,'S'=>667,'T'=>611,'U'=>722,'V'=>667,'W'=>944, 11 | 'X'=>667,'Y'=>667,'Z'=>611,'['=>278,'\\'=>278,']'=>278,'^'=>469,'_'=>556,'`'=>333,'a'=>556,'b'=>556,'c'=>500,'d'=>556,'e'=>556,'f'=>278,'g'=>556,'h'=>556,'i'=>222,'j'=>222,'k'=>500,'l'=>222,'m'=>833, 12 | 'n'=>556,'o'=>556,'p'=>556,'q'=>556,'r'=>333,'s'=>500,'t'=>278,'u'=>556,'v'=>500,'w'=>722,'x'=>500,'y'=>500,'z'=>500,'{'=>334,'|'=>260,'}'=>334,'~'=>584,chr(127)=>350,chr(128)=>556,chr(129)=>350,chr(130)=>222,chr(131)=>556, 13 | chr(132)=>333,chr(133)=>1000,chr(134)=>556,chr(135)=>556,chr(136)=>333,chr(137)=>1000,chr(138)=>667,chr(139)=>333,chr(140)=>1000,chr(141)=>350,chr(142)=>611,chr(143)=>350,chr(144)=>350,chr(145)=>222,chr(146)=>222,chr(147)=>333,chr(148)=>333,chr(149)=>350,chr(150)=>556,chr(151)=>1000,chr(152)=>333,chr(153)=>1000, 14 | chr(154)=>500,chr(155)=>333,chr(156)=>944,chr(157)=>350,chr(158)=>500,chr(159)=>667,chr(160)=>278,chr(161)=>333,chr(162)=>556,chr(163)=>556,chr(164)=>556,chr(165)=>556,chr(166)=>260,chr(167)=>556,chr(168)=>333,chr(169)=>737,chr(170)=>370,chr(171)=>556,chr(172)=>584,chr(173)=>333,chr(174)=>737,chr(175)=>333, 15 | chr(176)=>400,chr(177)=>584,chr(178)=>333,chr(179)=>333,chr(180)=>333,chr(181)=>556,chr(182)=>537,chr(183)=>278,chr(184)=>333,chr(185)=>333,chr(186)=>365,chr(187)=>556,chr(188)=>834,chr(189)=>834,chr(190)=>834,chr(191)=>611,chr(192)=>667,chr(193)=>667,chr(194)=>667,chr(195)=>667,chr(196)=>667,chr(197)=>667, 16 | chr(198)=>1000,chr(199)=>722,chr(200)=>667,chr(201)=>667,chr(202)=>667,chr(203)=>667,chr(204)=>278,chr(205)=>278,chr(206)=>278,chr(207)=>278,chr(208)=>722,chr(209)=>722,chr(210)=>778,chr(211)=>778,chr(212)=>778,chr(213)=>778,chr(214)=>778,chr(215)=>584,chr(216)=>778,chr(217)=>722,chr(218)=>722,chr(219)=>722, 17 | chr(220)=>722,chr(221)=>667,chr(222)=>667,chr(223)=>611,chr(224)=>556,chr(225)=>556,chr(226)=>556,chr(227)=>556,chr(228)=>556,chr(229)=>556,chr(230)=>889,chr(231)=>500,chr(232)=>556,chr(233)=>556,chr(234)=>556,chr(235)=>556,chr(236)=>278,chr(237)=>278,chr(238)=>278,chr(239)=>278,chr(240)=>556,chr(241)=>556, 18 | chr(242)=>556,chr(243)=>556,chr(244)=>556,chr(245)=>556,chr(246)=>556,chr(247)=>584,chr(248)=>611,chr(249)=>556,chr(250)=>556,chr(251)=>556,chr(252)=>556,chr(253)=>500,chr(254)=>556,chr(255)=>500); 19 | ?> 20 | -------------------------------------------------------------------------------- /src/classes/fpdf/font/timesb.php: -------------------------------------------------------------------------------- 1 | 250,chr(1)=>250,chr(2)=>250,chr(3)=>250,chr(4)=>250,chr(5)=>250,chr(6)=>250,chr(7)=>250,chr(8)=>250,chr(9)=>250,chr(10)=>250,chr(11)=>250,chr(12)=>250,chr(13)=>250,chr(14)=>250,chr(15)=>250,chr(16)=>250,chr(17)=>250,chr(18)=>250,chr(19)=>250,chr(20)=>250,chr(21)=>250, 8 | chr(22)=>250,chr(23)=>250,chr(24)=>250,chr(25)=>250,chr(26)=>250,chr(27)=>250,chr(28)=>250,chr(29)=>250,chr(30)=>250,chr(31)=>250,' '=>250,'!'=>333,'"'=>555,'#'=>500,'$'=>500,'%'=>1000,'&'=>833,'\''=>278,'('=>333,')'=>333,'*'=>500,'+'=>570, 9 | ','=>250,'-'=>333,'.'=>250,'/'=>278,'0'=>500,'1'=>500,'2'=>500,'3'=>500,'4'=>500,'5'=>500,'6'=>500,'7'=>500,'8'=>500,'9'=>500,':'=>333,';'=>333,'<'=>570,'='=>570,'>'=>570,'?'=>500,'@'=>930,'A'=>722, 10 | 'B'=>667,'C'=>722,'D'=>722,'E'=>667,'F'=>611,'G'=>778,'H'=>778,'I'=>389,'J'=>500,'K'=>778,'L'=>667,'M'=>944,'N'=>722,'O'=>778,'P'=>611,'Q'=>778,'R'=>722,'S'=>556,'T'=>667,'U'=>722,'V'=>722,'W'=>1000, 11 | 'X'=>722,'Y'=>722,'Z'=>667,'['=>333,'\\'=>278,']'=>333,'^'=>581,'_'=>500,'`'=>333,'a'=>500,'b'=>556,'c'=>444,'d'=>556,'e'=>444,'f'=>333,'g'=>500,'h'=>556,'i'=>278,'j'=>333,'k'=>556,'l'=>278,'m'=>833, 12 | 'n'=>556,'o'=>500,'p'=>556,'q'=>556,'r'=>444,'s'=>389,'t'=>333,'u'=>556,'v'=>500,'w'=>722,'x'=>500,'y'=>500,'z'=>444,'{'=>394,'|'=>220,'}'=>394,'~'=>520,chr(127)=>350,chr(128)=>500,chr(129)=>350,chr(130)=>333,chr(131)=>500, 13 | chr(132)=>500,chr(133)=>1000,chr(134)=>500,chr(135)=>500,chr(136)=>333,chr(137)=>1000,chr(138)=>556,chr(139)=>333,chr(140)=>1000,chr(141)=>350,chr(142)=>667,chr(143)=>350,chr(144)=>350,chr(145)=>333,chr(146)=>333,chr(147)=>500,chr(148)=>500,chr(149)=>350,chr(150)=>500,chr(151)=>1000,chr(152)=>333,chr(153)=>1000, 14 | chr(154)=>389,chr(155)=>333,chr(156)=>722,chr(157)=>350,chr(158)=>444,chr(159)=>722,chr(160)=>250,chr(161)=>333,chr(162)=>500,chr(163)=>500,chr(164)=>500,chr(165)=>500,chr(166)=>220,chr(167)=>500,chr(168)=>333,chr(169)=>747,chr(170)=>300,chr(171)=>500,chr(172)=>570,chr(173)=>333,chr(174)=>747,chr(175)=>333, 15 | chr(176)=>400,chr(177)=>570,chr(178)=>300,chr(179)=>300,chr(180)=>333,chr(181)=>556,chr(182)=>540,chr(183)=>250,chr(184)=>333,chr(185)=>300,chr(186)=>330,chr(187)=>500,chr(188)=>750,chr(189)=>750,chr(190)=>750,chr(191)=>500,chr(192)=>722,chr(193)=>722,chr(194)=>722,chr(195)=>722,chr(196)=>722,chr(197)=>722, 16 | chr(198)=>1000,chr(199)=>722,chr(200)=>667,chr(201)=>667,chr(202)=>667,chr(203)=>667,chr(204)=>389,chr(205)=>389,chr(206)=>389,chr(207)=>389,chr(208)=>722,chr(209)=>722,chr(210)=>778,chr(211)=>778,chr(212)=>778,chr(213)=>778,chr(214)=>778,chr(215)=>570,chr(216)=>778,chr(217)=>722,chr(218)=>722,chr(219)=>722, 17 | chr(220)=>722,chr(221)=>722,chr(222)=>611,chr(223)=>556,chr(224)=>500,chr(225)=>500,chr(226)=>500,chr(227)=>500,chr(228)=>500,chr(229)=>500,chr(230)=>722,chr(231)=>444,chr(232)=>444,chr(233)=>444,chr(234)=>444,chr(235)=>444,chr(236)=>278,chr(237)=>278,chr(238)=>278,chr(239)=>278,chr(240)=>500,chr(241)=>556, 18 | chr(242)=>500,chr(243)=>500,chr(244)=>500,chr(245)=>500,chr(246)=>500,chr(247)=>570,chr(248)=>500,chr(249)=>556,chr(250)=>556,chr(251)=>556,chr(252)=>556,chr(253)=>500,chr(254)=>556,chr(255)=>500); 19 | ?> 20 | -------------------------------------------------------------------------------- /src/classes/fpdf/font/helveticab.php: -------------------------------------------------------------------------------- 1 | 278,chr(1)=>278,chr(2)=>278,chr(3)=>278,chr(4)=>278,chr(5)=>278,chr(6)=>278,chr(7)=>278,chr(8)=>278,chr(9)=>278,chr(10)=>278,chr(11)=>278,chr(12)=>278,chr(13)=>278,chr(14)=>278,chr(15)=>278,chr(16)=>278,chr(17)=>278,chr(18)=>278,chr(19)=>278,chr(20)=>278,chr(21)=>278, 8 | chr(22)=>278,chr(23)=>278,chr(24)=>278,chr(25)=>278,chr(26)=>278,chr(27)=>278,chr(28)=>278,chr(29)=>278,chr(30)=>278,chr(31)=>278,' '=>278,'!'=>333,'"'=>474,'#'=>556,'$'=>556,'%'=>889,'&'=>722,'\''=>238,'('=>333,')'=>333,'*'=>389,'+'=>584, 9 | ','=>278,'-'=>333,'.'=>278,'/'=>278,'0'=>556,'1'=>556,'2'=>556,'3'=>556,'4'=>556,'5'=>556,'6'=>556,'7'=>556,'8'=>556,'9'=>556,':'=>333,';'=>333,'<'=>584,'='=>584,'>'=>584,'?'=>611,'@'=>975,'A'=>722, 10 | 'B'=>722,'C'=>722,'D'=>722,'E'=>667,'F'=>611,'G'=>778,'H'=>722,'I'=>278,'J'=>556,'K'=>722,'L'=>611,'M'=>833,'N'=>722,'O'=>778,'P'=>667,'Q'=>778,'R'=>722,'S'=>667,'T'=>611,'U'=>722,'V'=>667,'W'=>944, 11 | 'X'=>667,'Y'=>667,'Z'=>611,'['=>333,'\\'=>278,']'=>333,'^'=>584,'_'=>556,'`'=>333,'a'=>556,'b'=>611,'c'=>556,'d'=>611,'e'=>556,'f'=>333,'g'=>611,'h'=>611,'i'=>278,'j'=>278,'k'=>556,'l'=>278,'m'=>889, 12 | 'n'=>611,'o'=>611,'p'=>611,'q'=>611,'r'=>389,'s'=>556,'t'=>333,'u'=>611,'v'=>556,'w'=>778,'x'=>556,'y'=>556,'z'=>500,'{'=>389,'|'=>280,'}'=>389,'~'=>584,chr(127)=>350,chr(128)=>556,chr(129)=>350,chr(130)=>278,chr(131)=>556, 13 | chr(132)=>500,chr(133)=>1000,chr(134)=>556,chr(135)=>556,chr(136)=>333,chr(137)=>1000,chr(138)=>667,chr(139)=>333,chr(140)=>1000,chr(141)=>350,chr(142)=>611,chr(143)=>350,chr(144)=>350,chr(145)=>278,chr(146)=>278,chr(147)=>500,chr(148)=>500,chr(149)=>350,chr(150)=>556,chr(151)=>1000,chr(152)=>333,chr(153)=>1000, 14 | chr(154)=>556,chr(155)=>333,chr(156)=>944,chr(157)=>350,chr(158)=>500,chr(159)=>667,chr(160)=>278,chr(161)=>333,chr(162)=>556,chr(163)=>556,chr(164)=>556,chr(165)=>556,chr(166)=>280,chr(167)=>556,chr(168)=>333,chr(169)=>737,chr(170)=>370,chr(171)=>556,chr(172)=>584,chr(173)=>333,chr(174)=>737,chr(175)=>333, 15 | chr(176)=>400,chr(177)=>584,chr(178)=>333,chr(179)=>333,chr(180)=>333,chr(181)=>611,chr(182)=>556,chr(183)=>278,chr(184)=>333,chr(185)=>333,chr(186)=>365,chr(187)=>556,chr(188)=>834,chr(189)=>834,chr(190)=>834,chr(191)=>611,chr(192)=>722,chr(193)=>722,chr(194)=>722,chr(195)=>722,chr(196)=>722,chr(197)=>722, 16 | chr(198)=>1000,chr(199)=>722,chr(200)=>667,chr(201)=>667,chr(202)=>667,chr(203)=>667,chr(204)=>278,chr(205)=>278,chr(206)=>278,chr(207)=>278,chr(208)=>722,chr(209)=>722,chr(210)=>778,chr(211)=>778,chr(212)=>778,chr(213)=>778,chr(214)=>778,chr(215)=>584,chr(216)=>778,chr(217)=>722,chr(218)=>722,chr(219)=>722, 17 | chr(220)=>722,chr(221)=>667,chr(222)=>667,chr(223)=>611,chr(224)=>556,chr(225)=>556,chr(226)=>556,chr(227)=>556,chr(228)=>556,chr(229)=>556,chr(230)=>889,chr(231)=>556,chr(232)=>556,chr(233)=>556,chr(234)=>556,chr(235)=>556,chr(236)=>278,chr(237)=>278,chr(238)=>278,chr(239)=>278,chr(240)=>611,chr(241)=>611, 18 | chr(242)=>611,chr(243)=>611,chr(244)=>611,chr(245)=>611,chr(246)=>611,chr(247)=>584,chr(248)=>611,chr(249)=>611,chr(250)=>611,chr(251)=>611,chr(252)=>611,chr(253)=>556,chr(254)=>611,chr(255)=>556); 19 | ?> 20 | -------------------------------------------------------------------------------- /src/classes/fpdf/font/timesbi.php: -------------------------------------------------------------------------------- 1 | 250,chr(1)=>250,chr(2)=>250,chr(3)=>250,chr(4)=>250,chr(5)=>250,chr(6)=>250,chr(7)=>250,chr(8)=>250,chr(9)=>250,chr(10)=>250,chr(11)=>250,chr(12)=>250,chr(13)=>250,chr(14)=>250,chr(15)=>250,chr(16)=>250,chr(17)=>250,chr(18)=>250,chr(19)=>250,chr(20)=>250,chr(21)=>250, 8 | chr(22)=>250,chr(23)=>250,chr(24)=>250,chr(25)=>250,chr(26)=>250,chr(27)=>250,chr(28)=>250,chr(29)=>250,chr(30)=>250,chr(31)=>250,' '=>250,'!'=>389,'"'=>555,'#'=>500,'$'=>500,'%'=>833,'&'=>778,'\''=>278,'('=>333,')'=>333,'*'=>500,'+'=>570, 9 | ','=>250,'-'=>333,'.'=>250,'/'=>278,'0'=>500,'1'=>500,'2'=>500,'3'=>500,'4'=>500,'5'=>500,'6'=>500,'7'=>500,'8'=>500,'9'=>500,':'=>333,';'=>333,'<'=>570,'='=>570,'>'=>570,'?'=>500,'@'=>832,'A'=>667, 10 | 'B'=>667,'C'=>667,'D'=>722,'E'=>667,'F'=>667,'G'=>722,'H'=>778,'I'=>389,'J'=>500,'K'=>667,'L'=>611,'M'=>889,'N'=>722,'O'=>722,'P'=>611,'Q'=>722,'R'=>667,'S'=>556,'T'=>611,'U'=>722,'V'=>667,'W'=>889, 11 | 'X'=>667,'Y'=>611,'Z'=>611,'['=>333,'\\'=>278,']'=>333,'^'=>570,'_'=>500,'`'=>333,'a'=>500,'b'=>500,'c'=>444,'d'=>500,'e'=>444,'f'=>333,'g'=>500,'h'=>556,'i'=>278,'j'=>278,'k'=>500,'l'=>278,'m'=>778, 12 | 'n'=>556,'o'=>500,'p'=>500,'q'=>500,'r'=>389,'s'=>389,'t'=>278,'u'=>556,'v'=>444,'w'=>667,'x'=>500,'y'=>444,'z'=>389,'{'=>348,'|'=>220,'}'=>348,'~'=>570,chr(127)=>350,chr(128)=>500,chr(129)=>350,chr(130)=>333,chr(131)=>500, 13 | chr(132)=>500,chr(133)=>1000,chr(134)=>500,chr(135)=>500,chr(136)=>333,chr(137)=>1000,chr(138)=>556,chr(139)=>333,chr(140)=>944,chr(141)=>350,chr(142)=>611,chr(143)=>350,chr(144)=>350,chr(145)=>333,chr(146)=>333,chr(147)=>500,chr(148)=>500,chr(149)=>350,chr(150)=>500,chr(151)=>1000,chr(152)=>333,chr(153)=>1000, 14 | chr(154)=>389,chr(155)=>333,chr(156)=>722,chr(157)=>350,chr(158)=>389,chr(159)=>611,chr(160)=>250,chr(161)=>389,chr(162)=>500,chr(163)=>500,chr(164)=>500,chr(165)=>500,chr(166)=>220,chr(167)=>500,chr(168)=>333,chr(169)=>747,chr(170)=>266,chr(171)=>500,chr(172)=>606,chr(173)=>333,chr(174)=>747,chr(175)=>333, 15 | chr(176)=>400,chr(177)=>570,chr(178)=>300,chr(179)=>300,chr(180)=>333,chr(181)=>576,chr(182)=>500,chr(183)=>250,chr(184)=>333,chr(185)=>300,chr(186)=>300,chr(187)=>500,chr(188)=>750,chr(189)=>750,chr(190)=>750,chr(191)=>500,chr(192)=>667,chr(193)=>667,chr(194)=>667,chr(195)=>667,chr(196)=>667,chr(197)=>667, 16 | chr(198)=>944,chr(199)=>667,chr(200)=>667,chr(201)=>667,chr(202)=>667,chr(203)=>667,chr(204)=>389,chr(205)=>389,chr(206)=>389,chr(207)=>389,chr(208)=>722,chr(209)=>722,chr(210)=>722,chr(211)=>722,chr(212)=>722,chr(213)=>722,chr(214)=>722,chr(215)=>570,chr(216)=>722,chr(217)=>722,chr(218)=>722,chr(219)=>722, 17 | chr(220)=>722,chr(221)=>611,chr(222)=>611,chr(223)=>500,chr(224)=>500,chr(225)=>500,chr(226)=>500,chr(227)=>500,chr(228)=>500,chr(229)=>500,chr(230)=>722,chr(231)=>444,chr(232)=>444,chr(233)=>444,chr(234)=>444,chr(235)=>444,chr(236)=>278,chr(237)=>278,chr(238)=>278,chr(239)=>278,chr(240)=>500,chr(241)=>556, 18 | chr(242)=>500,chr(243)=>500,chr(244)=>500,chr(245)=>500,chr(246)=>500,chr(247)=>570,chr(248)=>500,chr(249)=>556,chr(250)=>556,chr(251)=>556,chr(252)=>556,chr(253)=>444,chr(254)=>500,chr(255)=>444); 19 | ?> 20 | -------------------------------------------------------------------------------- /src/classes/fpdf/font/helveticai.php: -------------------------------------------------------------------------------- 1 | 278,chr(1)=>278,chr(2)=>278,chr(3)=>278,chr(4)=>278,chr(5)=>278,chr(6)=>278,chr(7)=>278,chr(8)=>278,chr(9)=>278,chr(10)=>278,chr(11)=>278,chr(12)=>278,chr(13)=>278,chr(14)=>278,chr(15)=>278,chr(16)=>278,chr(17)=>278,chr(18)=>278,chr(19)=>278,chr(20)=>278,chr(21)=>278, 8 | chr(22)=>278,chr(23)=>278,chr(24)=>278,chr(25)=>278,chr(26)=>278,chr(27)=>278,chr(28)=>278,chr(29)=>278,chr(30)=>278,chr(31)=>278,' '=>278,'!'=>278,'"'=>355,'#'=>556,'$'=>556,'%'=>889,'&'=>667,'\''=>191,'('=>333,')'=>333,'*'=>389,'+'=>584, 9 | ','=>278,'-'=>333,'.'=>278,'/'=>278,'0'=>556,'1'=>556,'2'=>556,'3'=>556,'4'=>556,'5'=>556,'6'=>556,'7'=>556,'8'=>556,'9'=>556,':'=>278,';'=>278,'<'=>584,'='=>584,'>'=>584,'?'=>556,'@'=>1015,'A'=>667, 10 | 'B'=>667,'C'=>722,'D'=>722,'E'=>667,'F'=>611,'G'=>778,'H'=>722,'I'=>278,'J'=>500,'K'=>667,'L'=>556,'M'=>833,'N'=>722,'O'=>778,'P'=>667,'Q'=>778,'R'=>722,'S'=>667,'T'=>611,'U'=>722,'V'=>667,'W'=>944, 11 | 'X'=>667,'Y'=>667,'Z'=>611,'['=>278,'\\'=>278,']'=>278,'^'=>469,'_'=>556,'`'=>333,'a'=>556,'b'=>556,'c'=>500,'d'=>556,'e'=>556,'f'=>278,'g'=>556,'h'=>556,'i'=>222,'j'=>222,'k'=>500,'l'=>222,'m'=>833, 12 | 'n'=>556,'o'=>556,'p'=>556,'q'=>556,'r'=>333,'s'=>500,'t'=>278,'u'=>556,'v'=>500,'w'=>722,'x'=>500,'y'=>500,'z'=>500,'{'=>334,'|'=>260,'}'=>334,'~'=>584,chr(127)=>350,chr(128)=>556,chr(129)=>350,chr(130)=>222,chr(131)=>556, 13 | chr(132)=>333,chr(133)=>1000,chr(134)=>556,chr(135)=>556,chr(136)=>333,chr(137)=>1000,chr(138)=>667,chr(139)=>333,chr(140)=>1000,chr(141)=>350,chr(142)=>611,chr(143)=>350,chr(144)=>350,chr(145)=>222,chr(146)=>222,chr(147)=>333,chr(148)=>333,chr(149)=>350,chr(150)=>556,chr(151)=>1000,chr(152)=>333,chr(153)=>1000, 14 | chr(154)=>500,chr(155)=>333,chr(156)=>944,chr(157)=>350,chr(158)=>500,chr(159)=>667,chr(160)=>278,chr(161)=>333,chr(162)=>556,chr(163)=>556,chr(164)=>556,chr(165)=>556,chr(166)=>260,chr(167)=>556,chr(168)=>333,chr(169)=>737,chr(170)=>370,chr(171)=>556,chr(172)=>584,chr(173)=>333,chr(174)=>737,chr(175)=>333, 15 | chr(176)=>400,chr(177)=>584,chr(178)=>333,chr(179)=>333,chr(180)=>333,chr(181)=>556,chr(182)=>537,chr(183)=>278,chr(184)=>333,chr(185)=>333,chr(186)=>365,chr(187)=>556,chr(188)=>834,chr(189)=>834,chr(190)=>834,chr(191)=>611,chr(192)=>667,chr(193)=>667,chr(194)=>667,chr(195)=>667,chr(196)=>667,chr(197)=>667, 16 | chr(198)=>1000,chr(199)=>722,chr(200)=>667,chr(201)=>667,chr(202)=>667,chr(203)=>667,chr(204)=>278,chr(205)=>278,chr(206)=>278,chr(207)=>278,chr(208)=>722,chr(209)=>722,chr(210)=>778,chr(211)=>778,chr(212)=>778,chr(213)=>778,chr(214)=>778,chr(215)=>584,chr(216)=>778,chr(217)=>722,chr(218)=>722,chr(219)=>722, 17 | chr(220)=>722,chr(221)=>667,chr(222)=>667,chr(223)=>611,chr(224)=>556,chr(225)=>556,chr(226)=>556,chr(227)=>556,chr(228)=>556,chr(229)=>556,chr(230)=>889,chr(231)=>500,chr(232)=>556,chr(233)=>556,chr(234)=>556,chr(235)=>556,chr(236)=>278,chr(237)=>278,chr(238)=>278,chr(239)=>278,chr(240)=>556,chr(241)=>556, 18 | chr(242)=>556,chr(243)=>556,chr(244)=>556,chr(245)=>556,chr(246)=>556,chr(247)=>584,chr(248)=>611,chr(249)=>556,chr(250)=>556,chr(251)=>556,chr(252)=>556,chr(253)=>500,chr(254)=>556,chr(255)=>500); 19 | ?> 20 | -------------------------------------------------------------------------------- /src/classes/fpdf/font/helveticabi.php: -------------------------------------------------------------------------------- 1 | 278,chr(1)=>278,chr(2)=>278,chr(3)=>278,chr(4)=>278,chr(5)=>278,chr(6)=>278,chr(7)=>278,chr(8)=>278,chr(9)=>278,chr(10)=>278,chr(11)=>278,chr(12)=>278,chr(13)=>278,chr(14)=>278,chr(15)=>278,chr(16)=>278,chr(17)=>278,chr(18)=>278,chr(19)=>278,chr(20)=>278,chr(21)=>278, 8 | chr(22)=>278,chr(23)=>278,chr(24)=>278,chr(25)=>278,chr(26)=>278,chr(27)=>278,chr(28)=>278,chr(29)=>278,chr(30)=>278,chr(31)=>278,' '=>278,'!'=>333,'"'=>474,'#'=>556,'$'=>556,'%'=>889,'&'=>722,'\''=>238,'('=>333,')'=>333,'*'=>389,'+'=>584, 9 | ','=>278,'-'=>333,'.'=>278,'/'=>278,'0'=>556,'1'=>556,'2'=>556,'3'=>556,'4'=>556,'5'=>556,'6'=>556,'7'=>556,'8'=>556,'9'=>556,':'=>333,';'=>333,'<'=>584,'='=>584,'>'=>584,'?'=>611,'@'=>975,'A'=>722, 10 | 'B'=>722,'C'=>722,'D'=>722,'E'=>667,'F'=>611,'G'=>778,'H'=>722,'I'=>278,'J'=>556,'K'=>722,'L'=>611,'M'=>833,'N'=>722,'O'=>778,'P'=>667,'Q'=>778,'R'=>722,'S'=>667,'T'=>611,'U'=>722,'V'=>667,'W'=>944, 11 | 'X'=>667,'Y'=>667,'Z'=>611,'['=>333,'\\'=>278,']'=>333,'^'=>584,'_'=>556,'`'=>333,'a'=>556,'b'=>611,'c'=>556,'d'=>611,'e'=>556,'f'=>333,'g'=>611,'h'=>611,'i'=>278,'j'=>278,'k'=>556,'l'=>278,'m'=>889, 12 | 'n'=>611,'o'=>611,'p'=>611,'q'=>611,'r'=>389,'s'=>556,'t'=>333,'u'=>611,'v'=>556,'w'=>778,'x'=>556,'y'=>556,'z'=>500,'{'=>389,'|'=>280,'}'=>389,'~'=>584,chr(127)=>350,chr(128)=>556,chr(129)=>350,chr(130)=>278,chr(131)=>556, 13 | chr(132)=>500,chr(133)=>1000,chr(134)=>556,chr(135)=>556,chr(136)=>333,chr(137)=>1000,chr(138)=>667,chr(139)=>333,chr(140)=>1000,chr(141)=>350,chr(142)=>611,chr(143)=>350,chr(144)=>350,chr(145)=>278,chr(146)=>278,chr(147)=>500,chr(148)=>500,chr(149)=>350,chr(150)=>556,chr(151)=>1000,chr(152)=>333,chr(153)=>1000, 14 | chr(154)=>556,chr(155)=>333,chr(156)=>944,chr(157)=>350,chr(158)=>500,chr(159)=>667,chr(160)=>278,chr(161)=>333,chr(162)=>556,chr(163)=>556,chr(164)=>556,chr(165)=>556,chr(166)=>280,chr(167)=>556,chr(168)=>333,chr(169)=>737,chr(170)=>370,chr(171)=>556,chr(172)=>584,chr(173)=>333,chr(174)=>737,chr(175)=>333, 15 | chr(176)=>400,chr(177)=>584,chr(178)=>333,chr(179)=>333,chr(180)=>333,chr(181)=>611,chr(182)=>556,chr(183)=>278,chr(184)=>333,chr(185)=>333,chr(186)=>365,chr(187)=>556,chr(188)=>834,chr(189)=>834,chr(190)=>834,chr(191)=>611,chr(192)=>722,chr(193)=>722,chr(194)=>722,chr(195)=>722,chr(196)=>722,chr(197)=>722, 16 | chr(198)=>1000,chr(199)=>722,chr(200)=>667,chr(201)=>667,chr(202)=>667,chr(203)=>667,chr(204)=>278,chr(205)=>278,chr(206)=>278,chr(207)=>278,chr(208)=>722,chr(209)=>722,chr(210)=>778,chr(211)=>778,chr(212)=>778,chr(213)=>778,chr(214)=>778,chr(215)=>584,chr(216)=>778,chr(217)=>722,chr(218)=>722,chr(219)=>722, 17 | chr(220)=>722,chr(221)=>667,chr(222)=>667,chr(223)=>611,chr(224)=>556,chr(225)=>556,chr(226)=>556,chr(227)=>556,chr(228)=>556,chr(229)=>556,chr(230)=>889,chr(231)=>556,chr(232)=>556,chr(233)=>556,chr(234)=>556,chr(235)=>556,chr(236)=>278,chr(237)=>278,chr(238)=>278,chr(239)=>278,chr(240)=>611,chr(241)=>611, 18 | chr(242)=>611,chr(243)=>611,chr(244)=>611,chr(245)=>611,chr(246)=>611,chr(247)=>584,chr(248)=>611,chr(249)=>611,chr(250)=>611,chr(251)=>611,chr(252)=>611,chr(253)=>556,chr(254)=>611,chr(255)=>556); 19 | ?> 20 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ################# 2 | ## Eclipse 3 | ################# 4 | 5 | *.pydevproject 6 | .project 7 | .metadata 8 | bin/ 9 | tmp/ 10 | *.tmp 11 | *.bak 12 | *.swp 13 | *~.nib 14 | local.properties 15 | .classpath 16 | .settings/ 17 | .loadpath 18 | 19 | # External tool builders 20 | .externalToolBuilders/ 21 | 22 | # Locally stored "Eclipse launch configurations" 23 | *.launch 24 | 25 | # CDT-specific 26 | .cproject 27 | 28 | # PDT-specific 29 | .buildpath 30 | 31 | 32 | ################# 33 | ## Visual Studio 34 | ################# 35 | 36 | ## Ignore Visual Studio temporary files, build results, and 37 | ## files generated by popular Visual Studio add-ons. 38 | 39 | # User-specific files 40 | *.suo 41 | *.user 42 | *.sln.docstates 43 | 44 | # Build results 45 | 46 | [Dd]ebug/ 47 | [Rr]elease/ 48 | x64/ 49 | build/ 50 | [Bb]in/ 51 | [Oo]bj/ 52 | 53 | # MSTest test Results 54 | [Tt]est[Rr]esult*/ 55 | [Bb]uild[Ll]og.* 56 | 57 | *_i.c 58 | *_p.c 59 | *.ilk 60 | *.meta 61 | *.obj 62 | *.pch 63 | *.pdb 64 | *.pgc 65 | *.pgd 66 | *.rsp 67 | *.sbr 68 | *.tlb 69 | *.tli 70 | *.tlh 71 | *.tmp 72 | *.tmp_proj 73 | *.log 74 | *.vspscc 75 | *.vssscc 76 | .builds 77 | *.pidb 78 | *.log 79 | *.scc 80 | 81 | # Visual C++ cache files 82 | ipch/ 83 | *.aps 84 | *.ncb 85 | *.opensdf 86 | *.sdf 87 | *.cachefile 88 | 89 | # Visual Studio profiler 90 | *.psess 91 | *.vsp 92 | *.vspx 93 | 94 | # Guidance Automation Toolkit 95 | *.gpState 96 | 97 | # ReSharper is a .NET coding add-in 98 | _ReSharper*/ 99 | *.[Rr]e[Ss]harper 100 | 101 | # TeamCity is a build add-in 102 | _TeamCity* 103 | 104 | # DotCover is a Code Coverage Tool 105 | *.dotCover 106 | 107 | # NCrunch 108 | *.ncrunch* 109 | .*crunch*.local.xml 110 | 111 | # Installshield output folder 112 | [Ee]xpress/ 113 | 114 | # DocProject is a documentation generator add-in 115 | DocProject/buildhelp/ 116 | DocProject/Help/*.HxT 117 | DocProject/Help/*.HxC 118 | DocProject/Help/*.hhc 119 | DocProject/Help/*.hhk 120 | DocProject/Help/*.hhp 121 | DocProject/Help/Html2 122 | DocProject/Help/html 123 | 124 | # Click-Once directory 125 | publish/ 126 | 127 | # Publish Web Output 128 | *.Publish.xml 129 | *.pubxml 130 | 131 | # NuGet Packages Directory 132 | ## TODO: If you have NuGet Package Restore enabled, uncomment the next line 133 | #packages/ 134 | 135 | # Windows Azure Build Output 136 | csx 137 | *.build.csdef 138 | 139 | # Windows Store app package directory 140 | AppPackages/ 141 | 142 | # Others 143 | sql/ 144 | *.Cache 145 | ClientBin/ 146 | [Ss]tyle[Cc]op.* 147 | ~$* 148 | *~ 149 | *.dbmdl 150 | *.[Pp]ublish.xml 151 | *.pfx 152 | *.publishsettings 153 | 154 | # RIA/Silverlight projects 155 | Generated_Code/ 156 | 157 | # Backup & report files from converting an old project file to a newer 158 | # Visual Studio version. Backup files are not needed, because we have git ;-) 159 | _UpgradeReport_Files/ 160 | Backup*/ 161 | UpgradeLog*.XML 162 | UpgradeLog*.htm 163 | 164 | # SQL Server files 165 | App_Data/*.mdf 166 | App_Data/*.ldf 167 | 168 | ############# 169 | ## Windows detritus 170 | ############# 171 | 172 | # Windows image file caches 173 | Thumbs.db 174 | ehthumbs.db 175 | 176 | # Folder config file 177 | Desktop.ini 178 | 179 | # Recycle Bin used on file shares 180 | $RECYCLE.BIN/ 181 | 182 | # Mac crap 183 | .DS_Store 184 | 185 | 186 | ############# 187 | ## Python 188 | ############# 189 | 190 | *.py[co] 191 | 192 | # Packages 193 | *.egg 194 | *.egg-info 195 | dist/ 196 | build/ 197 | eggs/ 198 | parts/ 199 | var/ 200 | sdist/ 201 | develop-eggs/ 202 | .installed.cfg 203 | 204 | # Installer logs 205 | pip-log.txt 206 | 207 | # Unit test / coverage reports 208 | .coverage 209 | .tox 210 | 211 | #Translations 212 | *.mo 213 | 214 | #Mr Developer 215 | .mr.developer.cfg 216 | -------------------------------------------------------------------------------- /src/classes/usermanager.php: -------------------------------------------------------------------------------- 1 | mysqlconn=mysql_connect(MYSQL_HOST,MYSQL_USER,MYSQL_PWD); 12 | //mysql_select_db(MYSQL_DB,$this->mysqlconn); 13 | $this->mysqlconn=new mysqli(MYSQL_HOST,MYSQL_USER,MYSQL_PWD,MYSQL_DB); 14 | 15 | $this->existing_permissions=array('all','add_voucher','admin_login','drop_device','drop_voucher','sys_config','view_users','view_voucher', 16 | 'delete_users','edit_permissions','add_users','api_login'); 17 | } 18 | 19 | public function GetUserlist() 20 | { 21 | //$res=mysql_query('SELECT username FROM users ORDER BY username ASC',$this->mysqlconn); 22 | $qry='SELECT username FROM users ORDER BY username ASC'; 23 | $res=$this->mysqlconn->query($qry); 24 | $dataset=array(); 25 | while($row=$res->fetch_assoc()) 26 | { 27 | // Get permissions for this user 28 | //$perm_res=mysql_query('SELECT permission FROM permissions WHERE username="'.$row['username'].'" ORDER BY permission ASC'); 29 | $perm_qry='SELECT permission FROM permissions WHERE username="'.$this->mysqlconn->real_escape_string($row['username']).'" ORDER BY permission ASC'; 30 | $perm_res=$this->mysqlconn->query($perm_qry); 31 | $perm=''; 32 | while($perm_row=$perm_res->fetch_assoc()) // Build permission list 33 | { 34 | if($perm!='') 35 | { 36 | $perm=$perm.', '; 37 | } 38 | $perm=$perm.$perm_row['permission']; 39 | } 40 | $row['permission_list']=$perm; // Save permissions to array 41 | array_push($dataset,$row); 42 | } 43 | return $dataset; 44 | } 45 | 46 | public function AddUser($username,$pwd) 47 | { 48 | //@mysql_query('INSERT INTO users (username,pwd) VALUES ("'.$username.'","'.sha1($pwd).'")',$this->mysqlconn); 49 | $qry='INSERT INTO users (username,pwd) VALUES ("'.$this->mysqlconn->real_escape_string($username).'","'.sha1($this->mysqlconn->real_escape_string($pwd)).'")'; 50 | $this->mysqlconn->query($qry); 51 | } 52 | 53 | public function DeleteUser($username) 54 | { 55 | $this->mysqlconn->query('DELETE FROM users WHERE username="'.$this->mysqlconn->real_escape_string($username).'"'); 56 | $this->mysqlconn->query('DELETE FROM permissions WHERE username="'.$this->mysqlconn->real_escape_string($username).'"'); 57 | } 58 | 59 | public function GetPermissionList($user) 60 | { 61 | //$res=mysql_query('SELECT permission FROM permissions WHERE username="'.$user.'"',$this->mysqlconn); 62 | $qry='SELECT permission FROM permissions WHERE username="'.$this->mysqlconn->real_escape_string($user).'"'; 63 | $res=$this->mysqlconn->query($qry); 64 | $dataset=array(); 65 | while($row=$res->fetch_assoc()) 66 | { 67 | array_push($dataset,$row['permission']); 68 | } 69 | return $dataset; 70 | } 71 | 72 | public function AddPermission($user,$permission) 73 | { 74 | //@mysql_query('INSERT INTO permissions (username,permission) VALUES ("'.$user.'","'.$permission.'")',$this->mysqlconn); 75 | $this->mysqlconn->query('INSERT INTO permissions (username,permission) VALUES ("'.$this->mysqlconn->real_escape_string($user).'","'.$this->mysqlconn->real_escape_string($permission).'")'); 76 | } 77 | 78 | public function DropPermission($user,$permission) 79 | { 80 | //@mysql_query('DELETE FROM permissions WHERE permission="'.$permission.'" AND username="'.$user.'"',$this->mysqlconn); 81 | $this->mysqlconn->query('DELETE FROM permissions WHERE permission="'.$this->mysqlconn->real_escape_string($permission).'" AND username="'.$this->mysqlconn->real_escape_string($user).'"'); 82 | } 83 | 84 | public function GetExistingPermissions() // Get all permission levels that exist in OpenVoucher 85 | { 86 | return $this->existing_permissions; 87 | } 88 | } 89 | ?> 90 | -------------------------------------------------------------------------------- /src/classes/gui.php: -------------------------------------------------------------------------------- 1 | v = new vouchermanager(); // An own instance of vouchermanager is needed to query the devices that are connected to each voucher 9 | } 10 | 11 | private function secondsToTime($inputSeconds) { 12 | 13 | $secondsInAMinute = 60; 14 | $secondsInAnHour = 60 * $secondsInAMinute; 15 | $secondsInADay = 24 * $secondsInAnHour; 16 | 17 | // extract days 18 | $days = floor($inputSeconds / $secondsInADay); 19 | $days=(int)$days; 20 | 21 | // extract hours 22 | $hourSeconds = $inputSeconds % $secondsInADay; 23 | $hours = floor($hourSeconds / $secondsInAnHour); 24 | $hours=(int)$hours; 25 | 26 | // extract minutes 27 | $minuteSeconds = $hourSeconds % $secondsInAnHour; 28 | $minutes = floor($minuteSeconds / $secondsInAMinute); 29 | $minutes=(int)$minutes; 30 | 31 | // extract the remaining seconds 32 | $remainingSeconds = $minuteSeconds % $secondsInAMinute; 33 | $seconds = ceil($remainingSeconds); 34 | $seconds=(int)$seconds; 35 | 36 | $msg=''; 37 | 38 | if($days>0) 39 | { 40 | $msg=$days.' days'; 41 | } 42 | if($hours>0) 43 | { 44 | if(trim($msg)!='') 45 | { 46 | $msg=$msg.', '; 47 | } 48 | $msg=$msg.$hours.' hours'; 49 | } 50 | if($minutes>0) 51 | { 52 | if(trim($msg)!='') 53 | { 54 | $msg=$msg.', '; 55 | } 56 | $msg=$msg.$minutes.' minutes'; 57 | } 58 | if($seconds>0) 59 | { 60 | if(trim($msg)!='') 61 | { 62 | $msg=$msg.', '; 63 | } 64 | $msg=$msg.$seconds.' seconds'; 65 | } 66 | return $msg; 67 | } 68 | 69 | public function ListVouchers($dataset) 70 | { 71 | echo '
72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | '; 82 | 83 | $a=true; 84 | for($i=0;$i 95 | 96 | 97 | '; 98 | 99 | if($dataset[$i]['valid_until']!=0) 100 | { 101 | echo ''; 102 | } else { 103 | echo ''; 104 | } 105 | 106 | if($dataset[$i]['valid_for']!=0) 107 | { 108 | if($dataset[$i]['valid_until']!=0) // has the voucher been activated? 109 | { 110 | echo ''; // if it has, grey out the "valid_until" field 111 | } else { 112 | echo ''; 113 | } 114 | } else { 115 | echo ''; 116 | } 117 | echo ' 126 | 127 | '; 128 | } 129 | echo '
Voucher IDVerification keyDevice countValid untilValid forCommentDevicesDrop voucher
'.$dataset[$i]['voucher_id'].''.$dataset[$i]['verification_key'].''.$dataset[$i]['dev_count'].''.date('Y-m-d H:i',$dataset[$i]['valid_until']).'
Not activated yet
'.$this->secondsToTime($dataset[$i]['valid_for']).'
'.$this->secondsToTime($dataset[$i]['valid_for']).' '.$dataset[$i]['comment'].' '; 118 | 119 | $deviceinfo=$this->v->GetDeviceList($dataset[$i]['voucher_id']); 120 | for($j=0;$jDrop
'; 123 | } 124 | 125 | echo ' 
Drop voucher
'; 130 | } 131 | 132 | public function ListUsers($dataset) 133 | { 134 | echo '
135 | 136 | 137 | 138 | 139 | '; 140 | 141 | $a=true; 142 | for($i=0;$i 153 | 154 | 155 | 156 | '; 157 | } 158 | echo '
UsernamePermissionsDelete user
'.$dataset[$i]['username'].''.$dataset[$i]['permission_list'].' > Edit permissionsDelete user
'; 159 | } 160 | } 161 | ?> 162 | -------------------------------------------------------------------------------- /src/classes/adminauth.php: -------------------------------------------------------------------------------- 1 | mode=$mode; 15 | if($mode=='api') 16 | { 17 | ini_set("session.use_cookies",0); 18 | ini_set("session.use_trans_sid",1); 19 | session_id($_GET['session_id']); 20 | } 21 | $this->auth_ok=true; 22 | session_start(); 23 | 24 | //$this->mysqlconn=mysql_connect(MYSQL_HOST,MYSQL_USER,MYSQL_PWD); 25 | //mysql_select_db(MYSQL_DB,$this->mysqlconn); 26 | $this->mysqlconn=new mysqli(MYSQL_HOST,MYSQL_USER,MYSQL_PWD,MYSQL_DB); 27 | 28 | if(trim($_POST['user'])!='' && trim($_POST['pwd'])!='') // Got credentials from form - new user 29 | { 30 | // Get and check password 31 | //$res=mysql_query('SELECT username,pwd FROM users WHERE username="'.$_POST['user'].'"',$this->mysqlconn); 32 | $qry='SELECT username,pwd FROM users WHERE username="'.$this->mysqlconn->real_escape_string($_POST['user']).'"'; 33 | $res=$this->mysqlconn->query($qry); 34 | //$row=mysql_fetch_array($res); 35 | $row=$res->fetch_assoc(); 36 | if($row['pwd']!=sha1($_POST['pwd'])) // Password correct? 37 | { 38 | $this->auth_ok=false; // Not correct 39 | } else { 40 | $_SESSION['login']=$row['username']; // Password correct, start session 41 | setcookie('LastUsername', $row['username'], time()+31536000); // Remeber username for next login 42 | } 43 | } else { 44 | if(trim($_SESSION['login'])=='') // Is there an active session? 45 | { 46 | $this->auth_ok=false; // No active session, user has to login first 47 | } else { 48 | // There is an active session, we will check if the username is correct 49 | //$res=mysql_query('SELECT COUNT(*) AS cnt FROM users WHERE username="'.$_SESSION['login'].'"',$this->mysqlconn); 50 | $qry='SELECT COUNT(*) AS cnt FROM users WHERE username="'.$this->mysqlconn->real_escape_string($_SESSION['login']).'"'; 51 | $res=$this->mysqlconn->query($qry); 52 | //$row=mysql_fetch_array($res); 53 | $row=$res->fetch_assoc(); 54 | if($row['cnt']==0 || trim($row['cnt'])=='') 55 | { 56 | $this->auth_ok=false; // Username in session not found in database or database error 57 | echo 'user not found'; 58 | } 59 | } 60 | } 61 | 62 | if($this->auth_ok) // so far so good... 63 | { 64 | // ...but is the user allowed to log in via admin panel / api? 65 | if($mode=='api') 66 | { 67 | $this->auth_ok=$this->CheckPermission('api_login'); 68 | } else { 69 | $this->auth_ok=$this->CheckPermission('admin_login'); 70 | } 71 | } 72 | 73 | // If auth_ok has not been set to false until this point, the user is authenticated 74 | 75 | if(!$this->auth_ok) 76 | { 77 | if($mode=='api') 78 | { 79 | echo ' 80 | failed 81 | '; 82 | } else { 83 | include('../includes/header.php'); 84 | echo '
Please login
85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 |
Username:
Password: 93 |
94 |
95 | 96 | '; 97 | } 98 | die(); 99 | } 100 | 101 | if($mode=='api') 102 | { 103 | echo ' 104 | success 105 | '.session_id().' 106 | '; 107 | echo "\n"; 108 | } 109 | 110 | } 111 | 112 | public function Logout() 113 | { 114 | session_start(); 115 | $_SESSION = array(); 116 | session_destroy(); 117 | if($this->mode=='gui') 118 | { 119 | header('Location: index.php'); 120 | } 121 | if($this->mode=='api') 122 | { 123 | echo ' 124 | logout 125 | success 126 | '; 127 | echo "\n"; 128 | } 129 | } 130 | 131 | public function CheckPermission($permission) // Check if the logged in user has a specific permission 132 | { 133 | //$res=mysql_query('SELECT COUNT(*) AS cnt FROM permissions WHERE username="'.$_SESSION['login'].'" AND permission="all"',$this->mysqlconn); 134 | $qry='SELECT COUNT(*) AS cnt FROM permissions WHERE username="'.$this->mysqlconn->real_escape_string($_SESSION['login']).'" AND permission="all"'; 135 | //$row=mysql_fetch_array($res); 136 | $res=$this->mysqlconn->query($qry); 137 | $row=$res->fetch_assoc(); 138 | if($row['cnt']>0) 139 | { 140 | return true; 141 | } else { 142 | //$res=mysql_query('SELECT COUNT(*) AS cnt FROM permissions WHERE username="'.$_SESSION['login'].'" AND permission="'.$permission.'"',$this->mysqlconn); 143 | $qry='SELECT COUNT(*) AS cnt FROM permissions WHERE username="'.$this->mysqlconn->real_escape_string($_SESSION['login']).'" AND permission="'.$this->mysqlconn->real_escape_string($permission).'"'; 144 | $res=$this->mysqlconn->query($qry); 145 | //$row=mysql_fetch_array($res); 146 | $row=$res->fetch_assoc(); 147 | if($row['cnt']>0) 148 | { 149 | return true; 150 | } else { 151 | return false; 152 | } 153 | } 154 | } 155 | 156 | public function GetUsername() 157 | { 158 | return $_SESSION['login']; 159 | } 160 | } 161 | ?> 162 | -------------------------------------------------------------------------------- /src/admin/users.php: -------------------------------------------------------------------------------- 1 | CheckPermission('view_users')) 17 | { 18 | echo '
You have no permission to edit users.
'; 19 | die(); 20 | } 21 | 22 | echo '
User list


'; 23 | $agui->ListUsers($u->GetUserlist()); 24 | 25 | if($a->CheckPermission('add_users')) // Show form to add users if the client has permission to do so 26 | { 27 | echo '

'; 34 | } 35 | } 36 | 37 | if($_GET['do']=='add') // Requested to delete a user 38 | { 39 | if(!$a->CheckPermission('add_users')) 40 | { 41 | echo '
You have no permission to add users.
'; 42 | die(); 43 | } 44 | // Check the entered data 45 | if(trim($_POST['add_user'])=='') { die('No user given.'); } 46 | if($_POST['add_pwd']!=$_POST['add_repeat']) { die('The passwords do not match.'); } 47 | if(trim($_POST['add_pwd'])=='') { die('No password given.'); } 48 | 49 | $u->AddUser($_POST['add_user'],$_POST['add_pwd']); 50 | echo 'The user '.$_GET['add_user'].' has been added.'; 51 | } 52 | 53 | if($_GET['do']=='del') // Requested to delete a user 54 | { 55 | if(!$a->CheckPermission('delete_users')) 56 | { 57 | echo '
You have no permission to delete users.
'; 58 | die(); 59 | } 60 | 61 | if($_GET['user']=='') // No user given 62 | { 63 | echo '
No user given
'; 64 | die(); 65 | } 66 | if($_GET['confirm']=='y') // Did the user confirm the action? 67 | { 68 | if($_GET['user']==$_SESSION['login']) // The user is not allowed to delete himself 69 | { 70 | echo '
You cannot delete yourself. Please use another account to delete yours.
'; 71 | die(); 72 | } 73 | $u->DeleteUser($_GET['user']); // Delete the user 74 | echo 'The user '.$_GET['user'].' has been deleted.'; 75 | } else { 76 | echo '
Do you really want to delete the user "'.$_GET['user'].'"?

77 | Yes, do it!
'; 78 | } 79 | } 80 | 81 | if($_GET['do']=='edit_perm') 82 | { 83 | if(!$a->CheckPermission('edit_permissions')) 84 | { 85 | echo '
You have no permission to edit permissions.
'; 86 | die(); 87 | } 88 | if($_GET['user']==$_SESSION['login']) // The user is not allowed to delete himself 89 | { 90 | echo '
You cannot edit yourself. Please use another account to edit yours.
'; 91 | die(); 92 | } 93 | 94 | if($_GET['user']=='') die('No user given'); 95 | echo '
Permissions for user '.$_GET['user'].'


96 |

105 | 106 | 107 | Add permission:
'; 113 | } 114 | 115 | if($_GET['do']=='drop_permission') 116 | { 117 | if($_GET['user']==$_SESSION['login']) // The user is not allowed to delete himself 118 | { 119 | echo '
You cannot edit yourself. Please use another account to edit yours.
'; 120 | die(); 121 | } 122 | 123 | if(!$a->CheckPermission('edit_permissions')) 124 | { 125 | echo '
You are not allowed to edit permissions.
'; 126 | die(); 127 | } 128 | 129 | $u->DropPermission($_GET['user'],$_GET['permission']); 130 | echo 'Permission "'.$_GET['permission'].'" has been dropped for user "'.$_GET['user'].'"

131 | Back to user\'s permissions'; 132 | } 133 | if($_GET['do']=='add_permission') 134 | { 135 | if($_GET['user']==$_SESSION['login']) // The user is not allowed to delete himself 136 | { 137 | echo '
You cannot edit yourself. Please use another account to edit yours.
'; 138 | die(); 139 | } 140 | 141 | if(!$a->CheckPermission('edit_permissions')) 142 | { 143 | echo '
You are not allowed to edit permissions.
'; 144 | die(); 145 | } 146 | 147 | if($_GET['user']=='') die('No user given'); 148 | if($_GET['permission']=='') die('No permission given'); 149 | 150 | $u->AddPermission($_GET['user'],$_GET['permission']); 151 | echo 'Permission "'.$_GET['permission'].'" has been added for user "'.$_GET['user'].'"

152 | Back to user\'s permissions'; 153 | } 154 | ?> 155 | 156 | 157 | -------------------------------------------------------------------------------- /src/admin/api.php: -------------------------------------------------------------------------------- 1 | Logout(); 17 | } 18 | 19 | if($_GET['do']=='lstvouchers') 20 | { 21 | echo ''."\n"; 22 | if($auth->CheckPermission('view_voucher')) 23 | { 24 | echo "\t".'success'."\n"; 25 | $vouchers=$vouchermanager->GetVoucherList(); 26 | for($i=0;$i 29 | '.$vouchers[$i]['voucher_id'].' 30 | '.$vouchers[$i]['verification_key'].' 31 | '.$vouchers[$i]['dev_count'].' 32 | '.$vouchers[$i]['valid_until'].' 33 | '.$vouchers[$i]['comment'].' 34 | '."\n"; 35 | } 36 | } else { 37 | echo 'failed'; 38 | } 39 | echo ''; 40 | } 41 | 42 | if($_GET['lstdevices']) 43 | { 44 | echo ''."\n"; 45 | if($auth->CheckPermission('view_voucher') && isset($_GET['vid']) 46 | { 47 | echo "\t".'success'."\n"; 48 | $devices=$vouchermanager->GetDeviceList($_GET['vid']); 49 | foreach($devices as $device) 50 | { 51 | echo "\t".''."\n\t\t".''.$device['type'].''."\n\t\t".''.$device['addr'].''."\n\t".''."\n"; 52 | } 53 | } else { 54 | echo "\t".'failed'."\n"; 55 | } 56 | echo ''; 57 | } 58 | 59 | if($_GET['do']=='dropvoucher') 60 | { 61 | echo ''."\n\t".'dropvoucher'."\n"; 62 | if($auth->CheckPermission('drop_voucher')) 63 | { 64 | if(trim($_GET['vid'])=='') 65 | { 66 | echo "\t".'failed'."\n"; 67 | } else { 68 | echo "\t".'success'."\n"; 69 | $vouchermanager->DropVoucher($_GET['vid'],true); 70 | } 71 | } else { 72 | echo "\t".'failed'."\n"; 73 | } 74 | echo ''; 75 | } 76 | 77 | if($_GET['do']=='dropdevice') 78 | { 79 | echo ''."\n\t".'dropdevice'."\n"; 80 | 81 | if($auth->CheckPermission('drop_device')) 82 | { 83 | if(trim($_GET['type'])=='' || trim($_GET['addr'])=='') 84 | { 85 | echo "\t".'failed'."\n"; 86 | } else { 87 | echo "\t".'success'."\n"; 88 | $vouchermanager->DropDevice($_GET['type'],$_GET['addr']); 89 | } 90 | } else { 91 | 92 | } 93 | echo ''; 94 | } 95 | if($_GET['do']=='addvoucher') 96 | { 97 | echo ''."\n\t".'addvoucher'."\n"; 98 | 99 | if($auth->CheckPermission('add_voucher')) 100 | { 101 | if(!isset($_GET['devicecount']) || !is_numeric($_GET['devicecount']) || !isset($_GET['valid_until']) || !is_numeric($_GET['valid_until'])) 102 | { 103 | echo "\t".'failed'."\n"; 104 | } else { 105 | $vid=$vouchermanager->MakeVoucher($_GET['devicecount'],$_GET['valid_until'],$_GET['comment']); 106 | if($vid==0) 107 | { 108 | echo "\t".'failed'."\n"; 109 | } else { 110 | echo "\t".'success'."\n\t".''.$vid.''."\n"; 111 | } 112 | } 113 | } else { 114 | echo "\t".'failed'."\n"; 115 | } 116 | echo ''; 117 | } 118 | 119 | if($_GET['do']=='adduser') 120 | { 121 | echo ''."\n\t".'adduser'."\n"; 122 | if($auth->CheckPermission('add_users')) 123 | { 124 | if(!isset($_GET['user']) || !isset($_GET['pwd'])) 125 | { 126 | echo "\t".'failed'."\n"; 127 | } else { 128 | $usermanager->AddUser($_POST['add_user'],$_POST['add_pwd']); 129 | echo "\t".'success'."\n"; 130 | } 131 | } else { 132 | echo "\t".'failed'."\n"; 133 | } 134 | echo ''; 135 | } 136 | 137 | if($_GET['do']=='addpermission') 138 | { 139 | echo ''."\n\t".'addpermission'."\n"; 140 | if($auth->CheckPermission('edit_permissions')) 141 | { 142 | if(!isset($_GET['user']) || !isset($_GET['permission'])) 143 | { 144 | echo "\t".'failed'."\n"; 145 | } else { 146 | $usermanager->AddPermission($_GET['user'],$_GET['permission']); 147 | echo "\t".'success'."\n"; 148 | } 149 | } else { 150 | echo "\t".'failed'."\n"; 151 | } 152 | echo ''; 153 | } 154 | 155 | if($_GET['do']=='lstpermissions') 156 | { 157 | echo ''."\n"; 158 | if($auth->CheckPermission('edit_permissions')) 159 | { 160 | if(isset($_GET['user'])) 161 | { 162 | echo "\t".'success'."\n"; 163 | $permissions=$usermanager->GetPermissionList($_GET['user']); 164 | foreach($permissions as $permission) 165 | { 166 | echo "\t".''.$permission.''."\n"; 167 | } 168 | } else { 169 | echo "\t".'failed'."\n"; 170 | } 171 | } else { 172 | echo "\t".'failed'."\n"; 173 | } 174 | echo ''; 175 | } 176 | 177 | if($_GET['do']=='droppermission') 178 | { 179 | echo ''."\n\t".'droppermission'."\n"; 180 | if($auth->CheckPermission('edit_permissions')) 181 | { 182 | if(!isset($_GET['user']) || !isset($_GET['permission'])) 183 | { 184 | echo "\t".'failed'."\n"; 185 | } else { 186 | $usermanager->DropPermission($_GET['user'],$_GET['permission']); 187 | echo "\t".'success'."\n"; 188 | } 189 | } 190 | echo ''; 191 | } 192 | 193 | if($_GET['do']=='dropuser') 194 | { 195 | echo ''."\n\t".'dropuser'."\n"; 196 | if($auth->CheckPermission('delete_users')) 197 | { 198 | if(!isset($_GET['user'])) 199 | { 200 | echo "\t".'failed'."\n"; 201 | } else { 202 | $usermanager->DropPermissionDeleteUser($_GET['user']); 203 | echo "\t".'success'."\n"; 204 | } 205 | } 206 | echo ''; 207 | } 208 | 209 | if($_GET['do']=='lstusers') 210 | { 211 | echo ''."\n"; 212 | if($auth->CheckPermission('view_users')) 213 | { 214 | echo "\t".'success'."\n" 215 | $users=$usermanager->GetUserlist(); 216 | foreach($users as $user) 217 | { 218 | echo "\t".''."\n\t\t".''.$user['username'].''."\n\t\t".''.$user['permission_list'].''."\n\t".''; 219 | } 220 | } else { 221 | echo "\t".'failed'."\n"; 222 | } 223 | echo ''; 224 | } 225 | 226 | if($_GET['do']=='lstavailablepermissions') 227 | { 228 | echo ''."\n"; 229 | if($auth->CheckPermission('edit_permissions')) 230 | { 231 | echo "\t".'success'."\n"; 232 | $permissions=$usermanager->GetExistingPermissions(); 233 | foreach($permissions as $permission) 234 | { 235 | echo "\t".''.$permission.''."\n"; 236 | } 237 | } else { 238 | echo "\t".'failed'."\n"; 239 | } 240 | echo ''; 241 | } 242 | 243 | if($_GET['do']=='showversion') 244 | { 245 | if($versionmanager->UpdateAvailable()) 246 | { 247 | $update_av='y'; 248 | } else { 249 | $update_av='n'; 250 | } 251 | echo ''."\n\t".'success'."\n\t".''.$versionmanager->GetCurrentVersion().''."\n\t".''.$versionmanager->NewestVersion().''; 252 | echo "\n\t".''.$update_av.''."\n".''; 253 | } 254 | 255 | ?> 256 | -------------------------------------------------------------------------------- /src/admin/sysconfig.php: -------------------------------------------------------------------------------- 1 | CheckPermission('sys_config')) 9 | { 10 | require('../classes/gui.php'); 11 | include('../includes/header.php'); 12 | include('menu.php'); 13 | echo '
You have no permission to manage the system config.
'; 14 | die(); 15 | } 16 | 17 | include('../includes/header.php'); 18 | 19 | include('menu.php'); 20 | 21 | echo '
Manage system config


'; 22 | 23 | if($_GET['do']=='update_general') 24 | { 25 | $s->SetSetting('vouchertext1',$_POST['vouchertext1']); 26 | $s->SetSetting('vouchertext2',$_POST['vouchertext2']); 27 | $s->SetSetting('pre-form-text',$_POST['pre-form-text']); 28 | $s->SetSetting('post-form-text',$_POST['post-form-text']); 29 | $s->SetSetting('deny_drop_devices',$_POST['deny_drop_devices']); 30 | 31 | if($_POST['use_verification']=='y') 32 | { 33 | $s->SetSetting('use_verification','y'); 34 | } else { 35 | $s->SetSetting('use_verification','n'); 36 | } 37 | 38 | if($_POST['use_exp_date']=='y') 39 | { 40 | $s->SetSetting('use_exp_date','y'); 41 | } else { 42 | $s->SetSetting('use_exp_date','n'); 43 | } 44 | } 45 | 46 | if($_GET['do']=='update_default') 47 | { 48 | $s->SetSetting('default_voucher-qty',$_POST['qty']); 49 | $s->SetSetting('force_voucher-qty',$_POST['force_voucher-qty']); 50 | $s->SetSetting('default_device-qty',$_POST['qty_devices']); 51 | $s->SetSetting('force_device-qty',$_POST['force_device-qty']); 52 | $s->SetSetting('default_exp_d',$_POST['d']); 53 | $s->SetSetting('default_exp_h',$_POST['h']); 54 | $s->SetSetting('default_exp_m',$_POST['m']); 55 | $s->SetSetting('force_exp',$_POST['force_exp']); 56 | $s->SetSetting('default_start_exp',$_POST['start_exp']); 57 | $s->SetSetting('force_start_exp',$_POST['force_start_exp']); 58 | } 59 | 60 | if($_GET['do']=='logo') 61 | { 62 | move_uploaded_file($_FILES['logo']['tmp_name'],'../graphics/'.trim($_FILES['logo']['name'])); 63 | if(!preg_match("/image/i",$_FILES['logo']['type'])) 64 | { 65 | unlink('../graphics/'.trim($_FILES['logo']['name'])); 66 | die('The file doesn\'t seem to be a picture.'); 67 | } 68 | $s->SetSetting('logo',trim($_FILES['logo']['name'])); 69 | } 70 | 71 | if($_GET['do']=='del_logo') 72 | { 73 | $logo=$s->GetSetting('logo'); 74 | if(file_exists('../graphics/'.$logo) && !is_dir('../graphics/'.$logo)) 75 | { 76 | @unlink('../graphics/'.$logo); 77 | $s->SetSetting('logo',''); 78 | } 79 | } 80 | 81 | echo ' 82 | 83 | 84 | 85 | 88 | 89 | 92 | 93 | 96 | 97 | 100 | 101 | '; 102 | 103 | if($s->GetSetting('use_verification')=='y') 104 | { 105 | $veri_checked=' checked'; 106 | } else { 107 | $veri_checked=''; 108 | } 109 | 110 | echo ' 111 | 112 | '; 113 | 114 | if($s->GetSetting('use_exp_date')=='y') 115 | { 116 | $exp_checked=' checked'; 117 | } else { 118 | $exp_checked=''; 119 | } 120 | 121 | if($s->GetSetting('force_voucher-qty')=='y') 122 | { 123 | $force_voucher_qty_checked=' checked'; 124 | } else { 125 | $force_voucher_qty_checked=''; 126 | } 127 | 128 | if($s->GetSetting('force_device-qty')=='y') 129 | { 130 | $force_device_qty_checked=' checked'; 131 | } else { 132 | $force_device_qty_checked=''; 133 | } 134 | 135 | if($s->GetSetting('force_exp')=='y') 136 | { 137 | $force_exp_checked=' checked'; 138 | } else { 139 | $force_exp_checked=''; 140 | } 141 | 142 | if($s->GetSetting('force_start_exp')=='y') 143 | { 144 | $force_start_exp_checked=' checked'; 145 | } else { 146 | $force_start_exp_checked=''; 147 | } 148 | 149 | if($s->GetSetting('default_start_exp')=='creation') 150 | { 151 | $start_exp_creation_checked=' checked'; 152 | $start_exp_usage_checked=''; 153 | } else { 154 | $start_exp_creation_checked=''; 155 | $start_exp_usage_checked=' checked'; 156 | } 157 | 158 | if($s->GetSetting('deny_drop_devices')=='y') 159 | { 160 | $deny_drop_devices_checked=' checked'; 161 | } else { 162 | $deny_drop_devices_checked=''; 163 | } 164 | 165 | echo ' 166 | 167 |
General Settings
Voucher information text 1:
86 | First line of info text shown in the voucher. 87 |
Voucher information text 2:
90 | Second line of info text shown in the voucher. 91 |
Pre-form text:
94 | This text is shown on the landing page above the form. 95 |
Post-form text:
98 | This text is shown on the landing page below the form. 99 |
Use verification keys:
Use expiration date for voucher codes (instead of issue date):
Deny users to drop devices:
168 |
169 | 170 | 171 |

172 |
173 | 174 | 175 | 177 | 179 | 180 | 181 | 183 | 186 | 187 |
Change and enforce default values
Number of vouchers to create 176 | Enforce
Number of devices per voucher 178 | Enforce
Duration/Expiration of validity days, hours, 182 | minutes Enforce
Set expiration time of voucher On creation 184 | On first usage 185 | Enforce
188 |
189 | 190 |
191 | 192 |

193 | 194 | 195 | 196 | 208 | 213 |
Change logo
197 | Logo:'; 198 | 199 | $logo=$s->GetSetting('logo'); 200 | if(file_exists('../graphics/'.$logo) && !is_dir('../graphics/'.$logo)) 201 | { 202 | echo '
[Delete]'; 203 | } else { 204 | echo 'No image defined or not found'; 205 | } 206 | 207 | echo '
209 | You can upload a new logo here. This will overwrite your existing logo. 210 |
211 | 212 |
214 |
215 | 216 | 217 | '; -------------------------------------------------------------------------------- /src/admin/addvoucher.php: -------------------------------------------------------------------------------- 1 | CheckPermission('add_voucher')) 9 | { 10 | require('../classes/gui.php'); 11 | include('../includes/header.php'); 12 | include('menu.php'); 13 | echo '
You have no permission to add vouchers.
'; 14 | die(); 15 | } 16 | 17 | include('../includes/header.php'); 18 | 19 | include('menu.php'); 20 | 21 | // Has a number been entered or do we have to display the form? Has the user set how long the voucher should be valid? 22 | if((is_numeric($_POST['cnt']) && trim($_POST['cnt'])!='') && (($_POST['d']!=0 || $_POST['h']!=0 || $_POST['m']!=0) || ($_POST['e_d']!=0 || $_POST['e_h']!=0 || $_POST['e_m']!=0)) && ($_POST['start_expire']!='' || $s->GetSetting('force_start_exp')=='y')) 23 | { 24 | // Include and load the vouchermanager 25 | require('../classes/vouchermanager.php'); 26 | $v = new vouchermanager(); 27 | 28 | // Replace entered values with default values, if enforced. This prevents the user from injecting forbidden values to the system 29 | if($s->GetSetting('force_device-qty')=='y') 30 | { 31 | $_POST['dev-cnt']=$s->GetSetting('default_device-qty'); 32 | } 33 | if($s->GetSetting('force_start_exp')=='y') 34 | { 35 | if($s->GetSetting('default_start_exp')=='creation') 36 | { 37 | $_POST['start_expire']='now'; 38 | } else { 39 | $_POST['start_expire']='given'; 40 | } 41 | } 42 | if($s->GetSetting('force_exp')=='y') 43 | { 44 | $_POST['d']=$s->GetSetting('default_exp_d'); 45 | $_POST['e_d']=$_POST['d']; 46 | $_POST['h']=$s->GetSetting('default_exp_h'); 47 | $_POST['e_h']=$_POST['h']; 48 | $_POST['m']=$s->GetSetting('default_exp_m'); 49 | $_POST['e_m']=$_POST['m']; 50 | } 51 | if($s->GetSetting('force_voucher-qty')=='y') 52 | { 53 | $_POST['cnt']=$s->GetSetting('default_voucher-qty'); 54 | } 55 | 56 | if(!is_numeric($_POST['dev-cnt'])) $_POST['dev-cnt']=1; // Has the user enterered a numeric value for the device count? 57 | 58 | $voucher_ids=array(); 59 | 60 | if($_POST['start_expire']=='now') // Shall the voucher(s) start expiring instantly? 61 | { 62 | $valid_until=time()+($_POST['d']*86400)+($_POST['h']*3600)+($_POST['m']*60); // Calculate expiration time from now on 63 | $valid_for=0; 64 | } else { // Voucher shall start expiring at entering the code 65 | $valid_until=0; 66 | $valid_for=($_POST['e_d']*86400)+($_POST['e_h']*3600)+($_POST['e_m']*60); 67 | } 68 | for($i=1;$i<=$_POST['cnt'];$i++) 69 | { 70 | array_push($voucher_ids,$v->MakeVoucher($_POST['dev-cnt'],$valid_until,$valid_for,$_POST['comment'])); 71 | } 72 | echo '
The voucher(s) have been issued.


'; 73 | if($_POST['print']=='y') 74 | { 75 | $_SESSION['print_voucher_list']=$voucher_ids; 76 | echo ''; 77 | } 78 | echo 'The following voucher IDs have been issued:
'; 84 | } else { 85 | echo '
86 | 87 | 88 | 167 | 168 | 180 |
Number of vouchers to create'; 89 | 90 | if($s->GetSetting('force_voucher-qty')=='y') 91 | { 92 | echo ''; 93 | } else { 94 | echo ''; 95 | } 96 | 97 | echo '
98 | Duration/Expiration of validity 99 | '; 100 | 101 | if($s->GetSetting('default_start_exp')=='creation') 102 | { 103 | $exp_now_checked=' checked'; 104 | $exp_given_checked=''; 105 | } else { 106 | $exp_now_checked=''; 107 | $exp_given_checked=' checked'; 108 | } 109 | 110 | if($s->GetSetting('force_start_exp')=='y') 111 | { 112 | if($s->GetSetting('force_exp')=='y') 113 | { 114 | echo ' 116 | 117 | 118 | 121 | '; 122 | } else { 123 | echo ' 125 | 126 | 127 | 130 | '; 131 | } 132 | } else { 133 | if($s->GetSetting('force_exp')=='y') 134 | { 135 | echo ' 137 | 138 | 139 | 142 | '; 143 | } else { 144 | echo ' 146 | 147 | 148 | 151 | '; 152 | } 153 | } 154 | 155 | 156 | 157 | echo ' 158 |
Fixed expiration time days, hours, 115 | minutes
119 | days, hours, 120 | minutes after activating the voucher Fixed expiration time days, hours, 124 | minutes
128 | days, hours, 129 | minutes after activating the voucher Fixed expiration time days, hours, 136 | minutes
140 | days, hours, 141 | minutes after activating the voucher Fixed expiration time days, hours, 145 | minutes
149 | days, hours, 150 | minutes after activating the voucher
159 | 165 | 166 |
How many devices may the user register with this voucher?'; 169 | 170 | if($s->GetSetting('force_voucher-qty')=='y') 171 | { 172 | echo ''; 173 | } else { 174 | echo ''; 175 | } 176 | 177 | echo ' devices
178 | You may enter a comment if you with (e.g. the user\'s name): 179 |
181 |

182 | 183 | Print vouchers in PDF 184 |

'; 185 | } 186 | ?> 187 | -------------------------------------------------------------------------------- /src/classes/vouchermanager.php: -------------------------------------------------------------------------------- 1 | settings['mysql']['host']=MYSQL_HOST; 14 | $this->settings['mysql']['user']=MYSQL_USER; 15 | $this->settings['mysql']['pwd']=MYSQL_PWD; 16 | $this->settings['mysql']['db']=MYSQL_DB; 17 | 18 | $this->settings['system']['iptables']=SYSTEM_IPTABLES; 19 | $this->settings['system']['arp']=SYSTEM_ARP; 20 | $this->settings['system']['tmpdir']=SYSTEM_TMPDIR; 21 | 22 | $this->settings['system']['authentication']=SYSTEM_AUTHENTICATION; 23 | 24 | $this->settings['interfaces']['internal']=INTERFACES_INTERNAL; 25 | $this->settings['interfaces']['internal_ip']=INTERFACES_INTERNAL_IP; 26 | $this->settings['interfaces']['external']=INTERFACES_EXTERNAL; 27 | 28 | $this->settings['system']['demo']=OV_DEMO; 29 | 30 | $this->mysqlconn=new mysqli($this->settings['mysql']['host'],$this->settings['mysql']['user'],$this->settings['mysql']['pwd'],$this->settings['mysql']['db']); 31 | 32 | $this->sysconfig = new systemmanager(); 33 | } 34 | 35 | private function VoucherIDExists($vid) 36 | { 37 | $qry='SELECT COUNT(*) AS cnt FROM vouchers WHERE voucher_id="'.$this->mysqlconn->real_escape_string($vid).'"'; 38 | $res=$this->mysqlconn->query($qry); 39 | $row=$res->fetch_assoc(); 40 | if($row['cnt']>0) 41 | { 42 | return true; 43 | } else { 44 | return false; 45 | } 46 | } 47 | 48 | private function GetNewVoucherID($alt_date) 49 | { 50 | do 51 | { 52 | if(isset($alt_date) && $alt_date!='') 53 | { 54 | $vid_date=$alt_date; 55 | } else { 56 | $vid_date=time(); 57 | } 58 | $vid=date('Y-m-d',$vid_date).'-'.rand(111111,999999); 59 | } while($this->VoucherIDExists($vid)); 60 | return $vid; 61 | } 62 | 63 | private function GetNewVerificationKey() 64 | { 65 | return rand(111111,999999); 66 | } 67 | 68 | public function GetClientMAC($ipAddress='') 69 | { 70 | if($ipAddress=='') 71 | { 72 | $ipAddress=$_SERVER['REMOTE_ADDR']; 73 | } 74 | $macAddr=''; 75 | 76 | $arp=shell_exec($this->settings['system']['arp'].' -a '.$ipAddress); 77 | 78 | $x=strpos($arp,':'); 79 | $begin=$x-2; 80 | $macAddr=substr($arp,$begin,17); 81 | 82 | return $macAddr; 83 | } 84 | 85 | public function GetClientIP() 86 | { 87 | return $_SERVER['REMOTE_ADDR']; 88 | } 89 | 90 | public function BuildIPTables() 91 | { 92 | if(!$this->settings['system']['demo']) 93 | { 94 | $ipt='#!/bin/sh'."\n\n". 95 | 96 | 'IPTABLES=\'sudo '.$this->settings['system']['iptables'].'\''."\n". 97 | 'PORTAL_INT='.$this->settings['interfaces']['internal'].''."\n". 98 | 'OUTPUT_INT='.$this->settings['interfaces']['external'].''."\n\n". 99 | 100 | 101 | '# Flush (delete all rules in chain)'."\n". 102 | '$IPTABLES -F'."\n". 103 | '$IPTABLES -X'."\n". 104 | '$IPTABLES -t nat -F'."\n". 105 | '$IPTABLES -t nat -X'."\n". 106 | '$IPTABLES -t mangle -F'."\n". 107 | '$IPTABLES -t mangle -X'."\n". 108 | '$IPTABLES -P INPUT ACCEPT'."\n". 109 | '$IPTABLES -P FORWARD ACCEPT'."\n". 110 | '$IPTABLES -P OUTPUT ACCEPT'."\n\n". 111 | 112 | '# Chain for captive portal'."\n". 113 | '$IPTABLES -N captivePortal -t mangle'."\n". 114 | '$IPTABLES -t mangle -A PREROUTING -j captivePortal'."\n\n". 115 | 116 | '# List of allowed MAC addresses'."\n"; 117 | 118 | $qry='SELECT devices.addr FROM devices INNER JOIN vouchers ON devices.voucher_id=vouchers.voucher_id WHERE type="mac" AND valid_until>'.time(); 119 | $res=$this->mysqlconn->query($qry); 120 | while($row=$res->fetch_assoc()) 121 | { 122 | $ipt=$ipt.'$IPTABLES -t mangle -A captivePortal -m mac --mac-source '.$row['addr'].' -j RETURN'."\n"; 123 | } 124 | 125 | $ipt=$ipt."\n". 126 | '# List of allowed IP addresses'."\n"; 127 | 128 | $qry='SELECT devices.addr FROM devices INNER JOIN vouchers ON devices.voucher_id=vouchers.voucher_id WHERE type="ipv4" AND valid_until>'.time(); 129 | $res=$this->mysqlconn->query($qry); 130 | while($row=$res->fetch_assoc()) 131 | { 132 | $ipt=$ipt.'$IPTABLES -t mangle -A captivePortal -s '.$row['addr'].' -j RETURN'."\n"; 133 | } 134 | 135 | $ipt=$ipt."\n". 136 | '# DNS is allowed for all'."\n". 137 | '$IPTABLES -t mangle -A captivePortal -i $PORTAL_INT -p udp --dport 53 -j RETURN'."\n\n". 138 | '# Mark packets that are not allowed till here'."\n". 139 | '$IPTABLES -t mangle -A captivePortal -i $PORTAL_INT -j MARK --set-mark 99'."\n\n". 140 | '# Redirect unauthenticated clients to captive portal'."\n". 141 | '$IPTABLES -t nat -A PREROUTING -m mark --mark 99 -i $PORTAL_INT -p tcp --dport 80 -j DNAT --to-destination '.$this->settings['interfaces']['internal_ip']."\n\n". 142 | 143 | '# drop all marked with 99'."\n". 144 | '$IPTABLES -t filter -A FORWARD -m mark --mark 99 -j DROP'."\n\n". 145 | '# masquerading NAT'."\n". 146 | '$IPTABLES -t nat -A POSTROUTING -o $OUTPUT_INT -j MASQUERADE'; 147 | 148 | file_put_contents($this->settings['system']['tmpdir'].'iptables-autogen.sh',$ipt); 149 | shell_exec('chmod ugo+x '.$this->settings['system']['tmpdir'].'iptables-autogen.sh'); 150 | $runcmd=$this->settings['system']['tmpdir'].'iptables-autogen.sh'; 151 | shell_exec($runcmd); 152 | } 153 | } 154 | 155 | public function MakeVoucher($devicecount,$valid_until,$valid_for,$comment) 156 | { 157 | if($this->sysconfig->GetSetting('use_exp_date')=='y' && ($valid_for==0 || trim($valid_for)=='') && $valid_until!=0 && trim($valid_until)!='') 158 | { 159 | $vid_date=$valid_until; 160 | } else { 161 | $vid_date=time(); 162 | } 163 | $vid=$this->GetNewVoucherID($vid_date); 164 | 165 | if($this->sysconfig->GetSetting('use_verification')=='y') 166 | { 167 | $verification_key=$this->GetNewVerificationKey(); 168 | } else { 169 | $verification_key=''; 170 | } 171 | 172 | $qry='INSERT INTO vouchers (voucher_id,dev_count,valid_until,valid_for,verification_key,comment) VALUES ("'.$this->mysqlconn->real_escape_string($vid).'",'.$this->mysqlconn->real_escape_string($devicecount).','.$this->mysqlconn->real_escape_string($valid_until).','.$this->mysqlconn->real_escape_string($valid_for).',"'.$this->mysqlconn->real_escape_string($verification_key).'","'.$this->mysqlconn->real_escape_string($comment).'")'; 173 | if($this->mysqlconn->query($qry)) 174 | { 175 | return $vid; 176 | } else { 177 | return 0; 178 | } 179 | } 180 | 181 | public function DropVoucher($vid,$rebuild=true) 182 | { 183 | // Delete voucher from db 184 | $this->mysqlconn->query('DELETE FROM vouchers WHERE voucher_id="'.$this->mysqlconn->real_escape_string($vid).'"'); 185 | $this->mysqlconn->query('DELETE FROM devices WHERE voucher_id="'.$this->mysqlconn->real_escape_string($vid).'"'); 186 | if($this->mysqlconn->affected_rows>0) // if a device has been deleted, rebuild iptables 187 | { 188 | if($rebuild) 189 | { 190 | $this->BuildIPTables(); // only rebuild tables if it is necessary 191 | } 192 | } 193 | } 194 | 195 | public function DropOldVouchers() 196 | { 197 | // Look for expired vouchers in db 198 | $res=$this->mysqlconn->query('SELECT voucher_id FROM vouchers WHERE valid_until<'.time().' AND valid_until <> 0'); 199 | while($row=$res->fetch_assoc()) 200 | { 201 | // Drop found vouchers but do not rebuild iptables for each one. this would waste resources 202 | $this->DropVoucher($row['voucher_id'],false); 203 | } 204 | // After deletion, rebuild iptables once 205 | $this->BuildIPTables(); 206 | } 207 | 208 | // Find out the authentication method that should be used for the client 209 | public function GetAuthMethod() 210 | { 211 | return $this->settings['system']['authentication']; 212 | } 213 | 214 | // Check if a verification key is correct 215 | public function VerifyVoucherKey($vid,$verification_key) 216 | { 217 | $res=$this->mysqlconn->query('SELECT verification_key FROM vouchers WHERE voucher_id="'.$this->mysqlconn->real_escape_string($vid).'"'); 218 | $row=$res->fetch_assoc(); 219 | 220 | if($this->sysconfig->GetSetting('use_verification')=='y') 221 | { 222 | if($verification_key != $row['verification_key']) 223 | { 224 | return false; 225 | } else { 226 | return true; 227 | } 228 | } else { 229 | return true; 230 | } 231 | } 232 | 233 | public function AuthDevice($vid,$verification_key,$type,$addr) 234 | { 235 | // Voucher valid? 236 | $res=$this->mysqlconn->query('SELECT voucher_id,dev_count,valid_until,valid_for FROM vouchers WHERE voucher_id="'.$this->mysqlconn->real_escape_string($vid).'"'); 237 | $row=$res->fetch_assoc(); 238 | 239 | // Voucher not found 240 | if(trim($row['voucher_id'])=='') 241 | { 242 | return 'not-found-exceeded'; 243 | } 244 | 245 | if($this->sysconfig->GetSetting('use_verification')=='y') 246 | { 247 | if(!$this->VerifyVoucherKey($vid,$verification_key)) 248 | { 249 | return 'verification-failed'; 250 | } 251 | } 252 | 253 | // Voucher shall not expire before first use 254 | if($row['valid_for']!=0 && trim($row['valid_for']!='')) 255 | { 256 | $row['valid_until']=time()+$row['valid_for']; 257 | $this->mysqlconn->query('UPDATE vouchers SET valid_until='.$this->mysqlconn->real_escape_string($row['valid_until']).' WHERE voucher_id="'.$this->mysqlconn->real_escape_string($vid).'"'); 258 | } 259 | 260 | if($row['valid_until']<=time()) // Voucher exceeded 261 | { 262 | return 'not-found-exceeded'; 263 | } else { 264 | $res=$this->mysqlconn->query('SELECT COUNT(*) AS cnt FROM devices WHERE voucher_id="'.$this->mysqlconn->real_escape_string($vid).'"'); 265 | $row_dev=$res->fetch_assoc(); 266 | if(trim($row_dev['cnt'])=='' || $row_dev['cnt']>=$row['dev_count']) // Maximum number of devices reached or exceeded, or not able to get number of devices (database failure?) 267 | { 268 | return 'maxnumber-reached'; 269 | } else { 270 | if($this->mysqlconn->query('INSERT INTO devices VALUES ("'.$this->mysqlconn->real_escape_string($type).'","'.$this->mysqlconn->real_escape_string($addr).'","'.$this->mysqlconn->real_escape_string($vid).'")')) 271 | { 272 | $this->BuildIPTables(); 273 | return 'ok'; // Device has been authenticated 274 | } else { 275 | return 'db-error'; // Database error 276 | } 277 | } 278 | } 279 | } 280 | 281 | public function DropDevice($type,$addr) 282 | { 283 | if($type=='mac') 284 | { 285 | $this->mysqlconn->query('DELETE FROM devices WHERE type="mac" AND addr="'.$this->mysqlconn->real_escape_string($addr).'"'); 286 | if(!$this->settings['system']['demo']) shell_exec('sudo '.$this->settings['system']['iptables'].' -t mangle -D captivePortal -m mac --mac-source '.$addr.' -j RETURN'); 287 | } 288 | if($type=='ipv4') 289 | { 290 | $this->mysqlconn->query('DELETE FROM devices WHERE type="ipv4" AND addr="'.$this->mysqlconn->real_escape_string($addr).'"'); 291 | if(!$this->settings['system']['demo']) shell_exec('sudo '.$this->settings['system']['iptables'].' -t mangle -D captivePortal -s '.$addr.' -j RETURN'); 292 | } 293 | } 294 | 295 | // Return a list of all devices that are registered to a specific voucher 296 | public function GetDeviceList($vid) 297 | { 298 | $res=$this->mysqlconn->query('SELECT type,addr FROM devices WHERE voucher_id="'.$this->mysqlconn->real_escape_string($vid).'"'); 299 | $i=0; 300 | $devices=array(); 301 | while($row=$res->fetch_assoc()) 302 | { 303 | $devices[$i]=$row; 304 | $i++; 305 | } 306 | return $devices; 307 | } 308 | 309 | // Check if a specific device is registered to a specific voucher 310 | public function DeviceInVoucher($vid,$type,$addr) 311 | { 312 | $res=$this->mysqlconn->query('SELECT voucher_id FROM devices WHERE type="'.$this->mysqlconn->real_escape_string($type).'" AND addr="'.$this->mysqlconn->real_escape_string($addr).'"'); 313 | $row=$res->fetch_assoc(); 314 | if($row['voucher_id']==$vid) 315 | { 316 | return true; 317 | } else { 318 | return false; 319 | } 320 | } 321 | 322 | // Is the requesting client authenticated? 323 | public function ClientAuthenticated() 324 | { 325 | if($this->settings['system']['authentication']=='mac-only') 326 | { 327 | $addr=$this->GetClientMAC(); 328 | $type='mac'; 329 | } 330 | elseif($this->settings['system']['authentication']=='ipv4-only') 331 | { 332 | $addr=$this->GetClientIP(); 333 | $type='ipv4'; 334 | } 335 | 336 | $res=$this->mysqlconn->query('SELECT voucher_id FROM devices WHERE type="'.$this->mysqlconn->real_escape_string($type).'" AND addr="'.$this->mysqlconn->real_escape_string($addr).'"'); 337 | $row=$res->fetch_assoc(); 338 | if(trim($row['voucher_id'])!='') 339 | { 340 | return array($type,$addr,$row['voucher_id']); 341 | } else { 342 | return 'noauth'; 343 | } 344 | } 345 | 346 | // Get some voucher information from db 347 | public function GetVoucherInfo($vid) 348 | { 349 | $res=$this->mysqlconn->query('SELECT dev_count,valid_until,valid_for FROM vouchers WHERE voucher_id="'.$this->mysqlconn->real_escape_string($vid).'"'); 350 | $row=$res->fetch_assoc(); 351 | 352 | $res=$this->mysqlconn->query('SELECT COUNT(*) AS cnt FROM devices WHERE voucher_id="'.$this->mysqlconn->real_escape_string($vid).'"'); 353 | $cnt=$res->fetch_assoc(); 354 | 355 | $row['remain']=$row['dev_count']-$cnt['cnt']; // Calculate how many devices are left to register 356 | return $row; 357 | } 358 | 359 | // Generate a voucher list 360 | public function GetVoucherList($searchstring='') 361 | { 362 | $dataset=array(); 363 | $res=$this->mysqlconn->query('SELECT voucher_id,verification_key,dev_count,valid_until,valid_for,comment FROM vouchers '.$this->mysqlconn->real_escape_string($searchstring)); 364 | while($row=$res->fetch_assoc()) 365 | { 366 | array_push($dataset,$row); 367 | } 368 | return $dataset; 369 | } 370 | } 371 | ?> 372 | -------------------------------------------------------------------------------- /src/classes/fpdf/fpdf.php: -------------------------------------------------------------------------------- 1 | _dochecks(); 80 | // Initialization of properties 81 | $this->page = 0; 82 | $this->n = 2; 83 | $this->buffer = ''; 84 | $this->pages = array(); 85 | $this->PageSizes = array(); 86 | $this->state = 0; 87 | $this->fonts = array(); 88 | $this->FontFiles = array(); 89 | $this->diffs = array(); 90 | $this->images = array(); 91 | $this->links = array(); 92 | $this->InHeader = false; 93 | $this->InFooter = false; 94 | $this->lasth = 0; 95 | $this->FontFamily = ''; 96 | $this->FontStyle = ''; 97 | $this->FontSizePt = 12; 98 | $this->underline = false; 99 | $this->DrawColor = '0 G'; 100 | $this->FillColor = '0 g'; 101 | $this->TextColor = '0 g'; 102 | $this->ColorFlag = false; 103 | $this->ws = 0; 104 | // Font path 105 | if(defined('FPDF_FONTPATH')) 106 | { 107 | $this->fontpath = FPDF_FONTPATH; 108 | if(substr($this->fontpath,-1)!='/' && substr($this->fontpath,-1)!='\\') 109 | $this->fontpath .= '/'; 110 | } 111 | elseif(is_dir(dirname(__FILE__).'/font')) 112 | $this->fontpath = dirname(__FILE__).'/font/'; 113 | else 114 | $this->fontpath = ''; 115 | // Core fonts 116 | $this->CoreFonts = array('courier', 'helvetica', 'times', 'symbol', 'zapfdingbats'); 117 | // Scale factor 118 | if($unit=='pt') 119 | $this->k = 1; 120 | elseif($unit=='mm') 121 | $this->k = 72/25.4; 122 | elseif($unit=='cm') 123 | $this->k = 72/2.54; 124 | elseif($unit=='in') 125 | $this->k = 72; 126 | else 127 | $this->Error('Incorrect unit: '.$unit); 128 | // Page sizes 129 | $this->StdPageSizes = array('a3'=>array(841.89,1190.55), 'a4'=>array(595.28,841.89), 'a5'=>array(420.94,595.28), 130 | 'letter'=>array(612,792), 'legal'=>array(612,1008)); 131 | $size = $this->_getpagesize($size); 132 | $this->DefPageSize = $size; 133 | $this->CurPageSize = $size; 134 | // Page orientation 135 | $orientation = strtolower($orientation); 136 | if($orientation=='p' || $orientation=='portrait') 137 | { 138 | $this->DefOrientation = 'P'; 139 | $this->w = $size[0]; 140 | $this->h = $size[1]; 141 | } 142 | elseif($orientation=='l' || $orientation=='landscape') 143 | { 144 | $this->DefOrientation = 'L'; 145 | $this->w = $size[1]; 146 | $this->h = $size[0]; 147 | } 148 | else 149 | $this->Error('Incorrect orientation: '.$orientation); 150 | $this->CurOrientation = $this->DefOrientation; 151 | $this->wPt = $this->w*$this->k; 152 | $this->hPt = $this->h*$this->k; 153 | // Page margins (1 cm) 154 | $margin = 28.35/$this->k; 155 | $this->SetMargins($margin,$margin); 156 | // Interior cell margin (1 mm) 157 | $this->cMargin = $margin/10; 158 | // Line width (0.2 mm) 159 | $this->LineWidth = .567/$this->k; 160 | // Automatic page break 161 | $this->SetAutoPageBreak(true,2*$margin); 162 | // Default display mode 163 | $this->SetDisplayMode('default'); 164 | // Enable compression 165 | $this->SetCompression(true); 166 | // Set default PDF version number 167 | $this->PDFVersion = '1.3'; 168 | } 169 | 170 | function SetMargins($left, $top, $right=null) 171 | { 172 | // Set left, top and right margins 173 | $this->lMargin = $left; 174 | $this->tMargin = $top; 175 | if($right===null) 176 | $right = $left; 177 | $this->rMargin = $right; 178 | } 179 | 180 | function SetLeftMargin($margin) 181 | { 182 | // Set left margin 183 | $this->lMargin = $margin; 184 | if($this->page>0 && $this->x<$margin) 185 | $this->x = $margin; 186 | } 187 | 188 | function SetTopMargin($margin) 189 | { 190 | // Set top margin 191 | $this->tMargin = $margin; 192 | } 193 | 194 | function SetRightMargin($margin) 195 | { 196 | // Set right margin 197 | $this->rMargin = $margin; 198 | } 199 | 200 | function SetAutoPageBreak($auto, $margin=0) 201 | { 202 | // Set auto page break mode and triggering margin 203 | $this->AutoPageBreak = $auto; 204 | $this->bMargin = $margin; 205 | $this->PageBreakTrigger = $this->h-$margin; 206 | } 207 | 208 | function SetDisplayMode($zoom, $layout='default') 209 | { 210 | // Set display mode in viewer 211 | if($zoom=='fullpage' || $zoom=='fullwidth' || $zoom=='real' || $zoom=='default' || !is_string($zoom)) 212 | $this->ZoomMode = $zoom; 213 | else 214 | $this->Error('Incorrect zoom display mode: '.$zoom); 215 | if($layout=='single' || $layout=='continuous' || $layout=='two' || $layout=='default') 216 | $this->LayoutMode = $layout; 217 | else 218 | $this->Error('Incorrect layout display mode: '.$layout); 219 | } 220 | 221 | function SetCompression($compress) 222 | { 223 | // Set page compression 224 | if(function_exists('gzcompress')) 225 | $this->compress = $compress; 226 | else 227 | $this->compress = false; 228 | } 229 | 230 | function SetTitle($title, $isUTF8=false) 231 | { 232 | // Title of document 233 | if($isUTF8) 234 | $title = $this->_UTF8toUTF16($title); 235 | $this->title = $title; 236 | } 237 | 238 | function SetSubject($subject, $isUTF8=false) 239 | { 240 | // Subject of document 241 | if($isUTF8) 242 | $subject = $this->_UTF8toUTF16($subject); 243 | $this->subject = $subject; 244 | } 245 | 246 | function SetAuthor($author, $isUTF8=false) 247 | { 248 | // Author of document 249 | if($isUTF8) 250 | $author = $this->_UTF8toUTF16($author); 251 | $this->author = $author; 252 | } 253 | 254 | function SetKeywords($keywords, $isUTF8=false) 255 | { 256 | // Keywords of document 257 | if($isUTF8) 258 | $keywords = $this->_UTF8toUTF16($keywords); 259 | $this->keywords = $keywords; 260 | } 261 | 262 | function SetCreator($creator, $isUTF8=false) 263 | { 264 | // Creator of document 265 | if($isUTF8) 266 | $creator = $this->_UTF8toUTF16($creator); 267 | $this->creator = $creator; 268 | } 269 | 270 | function AliasNbPages($alias='{nb}') 271 | { 272 | // Define an alias for total number of pages 273 | $this->AliasNbPages = $alias; 274 | } 275 | 276 | function Error($msg) 277 | { 278 | // Fatal error 279 | die('FPDF error: '.$msg); 280 | } 281 | 282 | function Open() 283 | { 284 | // Begin document 285 | $this->state = 1; 286 | } 287 | 288 | function Close() 289 | { 290 | // Terminate document 291 | if($this->state==3) 292 | return; 293 | if($this->page==0) 294 | $this->AddPage(); 295 | // Page footer 296 | $this->InFooter = true; 297 | $this->Footer(); 298 | $this->InFooter = false; 299 | // Close page 300 | $this->_endpage(); 301 | // Close document 302 | $this->_enddoc(); 303 | } 304 | 305 | function AddPage($orientation='', $size='') 306 | { 307 | // Start a new page 308 | if($this->state==0) 309 | $this->Open(); 310 | $family = $this->FontFamily; 311 | $style = $this->FontStyle.($this->underline ? 'U' : ''); 312 | $fontsize = $this->FontSizePt; 313 | $lw = $this->LineWidth; 314 | $dc = $this->DrawColor; 315 | $fc = $this->FillColor; 316 | $tc = $this->TextColor; 317 | $cf = $this->ColorFlag; 318 | if($this->page>0) 319 | { 320 | // Page footer 321 | $this->InFooter = true; 322 | $this->Footer(); 323 | $this->InFooter = false; 324 | // Close page 325 | $this->_endpage(); 326 | } 327 | // Start new page 328 | $this->_beginpage($orientation,$size); 329 | // Set line cap style to square 330 | $this->_out('2 J'); 331 | // Set line width 332 | $this->LineWidth = $lw; 333 | $this->_out(sprintf('%.2F w',$lw*$this->k)); 334 | // Set font 335 | if($family) 336 | $this->SetFont($family,$style,$fontsize); 337 | // Set colors 338 | $this->DrawColor = $dc; 339 | if($dc!='0 G') 340 | $this->_out($dc); 341 | $this->FillColor = $fc; 342 | if($fc!='0 g') 343 | $this->_out($fc); 344 | $this->TextColor = $tc; 345 | $this->ColorFlag = $cf; 346 | // Page header 347 | $this->InHeader = true; 348 | $this->Header(); 349 | $this->InHeader = false; 350 | // Restore line width 351 | if($this->LineWidth!=$lw) 352 | { 353 | $this->LineWidth = $lw; 354 | $this->_out(sprintf('%.2F w',$lw*$this->k)); 355 | } 356 | // Restore font 357 | if($family) 358 | $this->SetFont($family,$style,$fontsize); 359 | // Restore colors 360 | if($this->DrawColor!=$dc) 361 | { 362 | $this->DrawColor = $dc; 363 | $this->_out($dc); 364 | } 365 | if($this->FillColor!=$fc) 366 | { 367 | $this->FillColor = $fc; 368 | $this->_out($fc); 369 | } 370 | $this->TextColor = $tc; 371 | $this->ColorFlag = $cf; 372 | } 373 | 374 | function Header() 375 | { 376 | // To be implemented in your own inherited class 377 | } 378 | 379 | function Footer() 380 | { 381 | // To be implemented in your own inherited class 382 | } 383 | 384 | function PageNo() 385 | { 386 | // Get current page number 387 | return $this->page; 388 | } 389 | 390 | function SetDrawColor($r, $g=null, $b=null) 391 | { 392 | // Set color for all stroking operations 393 | if(($r==0 && $g==0 && $b==0) || $g===null) 394 | $this->DrawColor = sprintf('%.3F G',$r/255); 395 | else 396 | $this->DrawColor = sprintf('%.3F %.3F %.3F RG',$r/255,$g/255,$b/255); 397 | if($this->page>0) 398 | $this->_out($this->DrawColor); 399 | } 400 | 401 | function SetFillColor($r, $g=null, $b=null) 402 | { 403 | // Set color for all filling operations 404 | if(($r==0 && $g==0 && $b==0) || $g===null) 405 | $this->FillColor = sprintf('%.3F g',$r/255); 406 | else 407 | $this->FillColor = sprintf('%.3F %.3F %.3F rg',$r/255,$g/255,$b/255); 408 | $this->ColorFlag = ($this->FillColor!=$this->TextColor); 409 | if($this->page>0) 410 | $this->_out($this->FillColor); 411 | } 412 | 413 | function SetTextColor($r, $g=null, $b=null) 414 | { 415 | // Set color for text 416 | if(($r==0 && $g==0 && $b==0) || $g===null) 417 | $this->TextColor = sprintf('%.3F g',$r/255); 418 | else 419 | $this->TextColor = sprintf('%.3F %.3F %.3F rg',$r/255,$g/255,$b/255); 420 | $this->ColorFlag = ($this->FillColor!=$this->TextColor); 421 | } 422 | 423 | function GetStringWidth($s) 424 | { 425 | // Get width of a string in the current font 426 | $s = (string)$s; 427 | $cw = &$this->CurrentFont['cw']; 428 | $w = 0; 429 | $l = strlen($s); 430 | for($i=0;$i<$l;$i++) 431 | $w += $cw[$s[$i]]; 432 | return $w*$this->FontSize/1000; 433 | } 434 | 435 | function SetLineWidth($width) 436 | { 437 | // Set line width 438 | $this->LineWidth = $width; 439 | if($this->page>0) 440 | $this->_out(sprintf('%.2F w',$width*$this->k)); 441 | } 442 | 443 | function Line($x1, $y1, $x2, $y2) 444 | { 445 | // Draw a line 446 | $this->_out(sprintf('%.2F %.2F m %.2F %.2F l S',$x1*$this->k,($this->h-$y1)*$this->k,$x2*$this->k,($this->h-$y2)*$this->k)); 447 | } 448 | 449 | function Rect($x, $y, $w, $h, $style='') 450 | { 451 | // Draw a rectangle 452 | if($style=='F') 453 | $op = 'f'; 454 | elseif($style=='FD' || $style=='DF') 455 | $op = 'B'; 456 | else 457 | $op = 'S'; 458 | $this->_out(sprintf('%.2F %.2F %.2F %.2F re %s',$x*$this->k,($this->h-$y)*$this->k,$w*$this->k,-$h*$this->k,$op)); 459 | } 460 | 461 | function AddFont($family, $style='', $file='') 462 | { 463 | // Add a TrueType, OpenType or Type1 font 464 | $family = strtolower($family); 465 | if($file=='') 466 | $file = str_replace(' ','',$family).strtolower($style).'.php'; 467 | $style = strtoupper($style); 468 | if($style=='IB') 469 | $style = 'BI'; 470 | $fontkey = $family.$style; 471 | if(isset($this->fonts[$fontkey])) 472 | return; 473 | $info = $this->_loadfont($file); 474 | $info['i'] = count($this->fonts)+1; 475 | if(!empty($info['diff'])) 476 | { 477 | // Search existing encodings 478 | $n = array_search($info['diff'],$this->diffs); 479 | if(!$n) 480 | { 481 | $n = count($this->diffs)+1; 482 | $this->diffs[$n] = $info['diff']; 483 | } 484 | $info['diffn'] = $n; 485 | } 486 | if(!empty($info['file'])) 487 | { 488 | // Embedded font 489 | if($info['type']=='TrueType') 490 | $this->FontFiles[$info['file']] = array('length1'=>$info['originalsize']); 491 | else 492 | $this->FontFiles[$info['file']] = array('length1'=>$info['size1'], 'length2'=>$info['size2']); 493 | } 494 | $this->fonts[$fontkey] = $info; 495 | } 496 | 497 | function SetFont($family, $style='', $size=0) 498 | { 499 | // Select a font; size given in points 500 | if($family=='') 501 | $family = $this->FontFamily; 502 | else 503 | $family = strtolower($family); 504 | $style = strtoupper($style); 505 | if(strpos($style,'U')!==false) 506 | { 507 | $this->underline = true; 508 | $style = str_replace('U','',$style); 509 | } 510 | else 511 | $this->underline = false; 512 | if($style=='IB') 513 | $style = 'BI'; 514 | if($size==0) 515 | $size = $this->FontSizePt; 516 | // Test if font is already selected 517 | if($this->FontFamily==$family && $this->FontStyle==$style && $this->FontSizePt==$size) 518 | return; 519 | // Test if font is already loaded 520 | $fontkey = $family.$style; 521 | if(!isset($this->fonts[$fontkey])) 522 | { 523 | // Test if one of the core fonts 524 | if($family=='arial') 525 | $family = 'helvetica'; 526 | if(in_array($family,$this->CoreFonts)) 527 | { 528 | if($family=='symbol' || $family=='zapfdingbats') 529 | $style = ''; 530 | $fontkey = $family.$style; 531 | if(!isset($this->fonts[$fontkey])) 532 | $this->AddFont($family,$style); 533 | } 534 | else 535 | $this->Error('Undefined font: '.$family.' '.$style); 536 | } 537 | // Select it 538 | $this->FontFamily = $family; 539 | $this->FontStyle = $style; 540 | $this->FontSizePt = $size; 541 | $this->FontSize = $size/$this->k; 542 | $this->CurrentFont = &$this->fonts[$fontkey]; 543 | if($this->page>0) 544 | $this->_out(sprintf('BT /F%d %.2F Tf ET',$this->CurrentFont['i'],$this->FontSizePt)); 545 | } 546 | 547 | function SetFontSize($size) 548 | { 549 | // Set font size in points 550 | if($this->FontSizePt==$size) 551 | return; 552 | $this->FontSizePt = $size; 553 | $this->FontSize = $size/$this->k; 554 | if($this->page>0) 555 | $this->_out(sprintf('BT /F%d %.2F Tf ET',$this->CurrentFont['i'],$this->FontSizePt)); 556 | } 557 | 558 | function AddLink() 559 | { 560 | // Create a new internal link 561 | $n = count($this->links)+1; 562 | $this->links[$n] = array(0, 0); 563 | return $n; 564 | } 565 | 566 | function SetLink($link, $y=0, $page=-1) 567 | { 568 | // Set destination of internal link 569 | if($y==-1) 570 | $y = $this->y; 571 | if($page==-1) 572 | $page = $this->page; 573 | $this->links[$link] = array($page, $y); 574 | } 575 | 576 | function Link($x, $y, $w, $h, $link) 577 | { 578 | // Put a link on the page 579 | $this->PageLinks[$this->page][] = array($x*$this->k, $this->hPt-$y*$this->k, $w*$this->k, $h*$this->k, $link); 580 | } 581 | 582 | function Text($x, $y, $txt) 583 | { 584 | // Output a string 585 | $s = sprintf('BT %.2F %.2F Td (%s) Tj ET',$x*$this->k,($this->h-$y)*$this->k,$this->_escape($txt)); 586 | if($this->underline && $txt!='') 587 | $s .= ' '.$this->_dounderline($x,$y,$txt); 588 | if($this->ColorFlag) 589 | $s = 'q '.$this->TextColor.' '.$s.' Q'; 590 | $this->_out($s); 591 | } 592 | 593 | function AcceptPageBreak() 594 | { 595 | // Accept automatic page break or not 596 | return $this->AutoPageBreak; 597 | } 598 | 599 | function Cell($w, $h=0, $txt='', $border=0, $ln=0, $align='', $fill=false, $link='') 600 | { 601 | // Output a cell 602 | $k = $this->k; 603 | if($this->y+$h>$this->PageBreakTrigger && !$this->InHeader && !$this->InFooter && $this->AcceptPageBreak()) 604 | { 605 | // Automatic page break 606 | $x = $this->x; 607 | $ws = $this->ws; 608 | if($ws>0) 609 | { 610 | $this->ws = 0; 611 | $this->_out('0 Tw'); 612 | } 613 | $this->AddPage($this->CurOrientation,$this->CurPageSize); 614 | $this->x = $x; 615 | if($ws>0) 616 | { 617 | $this->ws = $ws; 618 | $this->_out(sprintf('%.3F Tw',$ws*$k)); 619 | } 620 | } 621 | if($w==0) 622 | $w = $this->w-$this->rMargin-$this->x; 623 | $s = ''; 624 | if($fill || $border==1) 625 | { 626 | if($fill) 627 | $op = ($border==1) ? 'B' : 'f'; 628 | else 629 | $op = 'S'; 630 | $s = sprintf('%.2F %.2F %.2F %.2F re %s ',$this->x*$k,($this->h-$this->y)*$k,$w*$k,-$h*$k,$op); 631 | } 632 | if(is_string($border)) 633 | { 634 | $x = $this->x; 635 | $y = $this->y; 636 | if(strpos($border,'L')!==false) 637 | $s .= sprintf('%.2F %.2F m %.2F %.2F l S ',$x*$k,($this->h-$y)*$k,$x*$k,($this->h-($y+$h))*$k); 638 | if(strpos($border,'T')!==false) 639 | $s .= sprintf('%.2F %.2F m %.2F %.2F l S ',$x*$k,($this->h-$y)*$k,($x+$w)*$k,($this->h-$y)*$k); 640 | if(strpos($border,'R')!==false) 641 | $s .= sprintf('%.2F %.2F m %.2F %.2F l S ',($x+$w)*$k,($this->h-$y)*$k,($x+$w)*$k,($this->h-($y+$h))*$k); 642 | if(strpos($border,'B')!==false) 643 | $s .= sprintf('%.2F %.2F m %.2F %.2F l S ',$x*$k,($this->h-($y+$h))*$k,($x+$w)*$k,($this->h-($y+$h))*$k); 644 | } 645 | if($txt!=='') 646 | { 647 | if($align=='R') 648 | $dx = $w-$this->cMargin-$this->GetStringWidth($txt); 649 | elseif($align=='C') 650 | $dx = ($w-$this->GetStringWidth($txt))/2; 651 | else 652 | $dx = $this->cMargin; 653 | if($this->ColorFlag) 654 | $s .= 'q '.$this->TextColor.' '; 655 | $txt2 = str_replace(')','\\)',str_replace('(','\\(',str_replace('\\','\\\\',$txt))); 656 | $s .= sprintf('BT %.2F %.2F Td (%s) Tj ET',($this->x+$dx)*$k,($this->h-($this->y+.5*$h+.3*$this->FontSize))*$k,$txt2); 657 | if($this->underline) 658 | $s .= ' '.$this->_dounderline($this->x+$dx,$this->y+.5*$h+.3*$this->FontSize,$txt); 659 | if($this->ColorFlag) 660 | $s .= ' Q'; 661 | if($link) 662 | $this->Link($this->x+$dx,$this->y+.5*$h-.5*$this->FontSize,$this->GetStringWidth($txt),$this->FontSize,$link); 663 | } 664 | if($s) 665 | $this->_out($s); 666 | $this->lasth = $h; 667 | if($ln>0) 668 | { 669 | // Go to next line 670 | $this->y += $h; 671 | if($ln==1) 672 | $this->x = $this->lMargin; 673 | } 674 | else 675 | $this->x += $w; 676 | } 677 | 678 | function MultiCell($w, $h, $txt, $border=0, $align='J', $fill=false) 679 | { 680 | // Output text with automatic or explicit line breaks 681 | $cw = &$this->CurrentFont['cw']; 682 | if($w==0) 683 | $w = $this->w-$this->rMargin-$this->x; 684 | $wmax = ($w-2*$this->cMargin)*1000/$this->FontSize; 685 | $s = str_replace("\r",'',$txt); 686 | $nb = strlen($s); 687 | if($nb>0 && $s[$nb-1]=="\n") 688 | $nb--; 689 | $b = 0; 690 | if($border) 691 | { 692 | if($border==1) 693 | { 694 | $border = 'LTRB'; 695 | $b = 'LRT'; 696 | $b2 = 'LR'; 697 | } 698 | else 699 | { 700 | $b2 = ''; 701 | if(strpos($border,'L')!==false) 702 | $b2 .= 'L'; 703 | if(strpos($border,'R')!==false) 704 | $b2 .= 'R'; 705 | $b = (strpos($border,'T')!==false) ? $b2.'T' : $b2; 706 | } 707 | } 708 | $sep = -1; 709 | $i = 0; 710 | $j = 0; 711 | $l = 0; 712 | $ns = 0; 713 | $nl = 1; 714 | while($i<$nb) 715 | { 716 | // Get next character 717 | $c = $s[$i]; 718 | if($c=="\n") 719 | { 720 | // Explicit line break 721 | if($this->ws>0) 722 | { 723 | $this->ws = 0; 724 | $this->_out('0 Tw'); 725 | } 726 | $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill); 727 | $i++; 728 | $sep = -1; 729 | $j = $i; 730 | $l = 0; 731 | $ns = 0; 732 | $nl++; 733 | if($border && $nl==2) 734 | $b = $b2; 735 | continue; 736 | } 737 | if($c==' ') 738 | { 739 | $sep = $i; 740 | $ls = $l; 741 | $ns++; 742 | } 743 | $l += $cw[$c]; 744 | if($l>$wmax) 745 | { 746 | // Automatic line break 747 | if($sep==-1) 748 | { 749 | if($i==$j) 750 | $i++; 751 | if($this->ws>0) 752 | { 753 | $this->ws = 0; 754 | $this->_out('0 Tw'); 755 | } 756 | $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill); 757 | } 758 | else 759 | { 760 | if($align=='J') 761 | { 762 | $this->ws = ($ns>1) ? ($wmax-$ls)/1000*$this->FontSize/($ns-1) : 0; 763 | $this->_out(sprintf('%.3F Tw',$this->ws*$this->k)); 764 | } 765 | $this->Cell($w,$h,substr($s,$j,$sep-$j),$b,2,$align,$fill); 766 | $i = $sep+1; 767 | } 768 | $sep = -1; 769 | $j = $i; 770 | $l = 0; 771 | $ns = 0; 772 | $nl++; 773 | if($border && $nl==2) 774 | $b = $b2; 775 | } 776 | else 777 | $i++; 778 | } 779 | // Last chunk 780 | if($this->ws>0) 781 | { 782 | $this->ws = 0; 783 | $this->_out('0 Tw'); 784 | } 785 | if($border && strpos($border,'B')!==false) 786 | $b .= 'B'; 787 | $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill); 788 | $this->x = $this->lMargin; 789 | } 790 | 791 | function Write($h, $txt, $link='') 792 | { 793 | // Output text in flowing mode 794 | $cw = &$this->CurrentFont['cw']; 795 | $w = $this->w-$this->rMargin-$this->x; 796 | $wmax = ($w-2*$this->cMargin)*1000/$this->FontSize; 797 | $s = str_replace("\r",'',$txt); 798 | $nb = strlen($s); 799 | $sep = -1; 800 | $i = 0; 801 | $j = 0; 802 | $l = 0; 803 | $nl = 1; 804 | while($i<$nb) 805 | { 806 | // Get next character 807 | $c = $s[$i]; 808 | if($c=="\n") 809 | { 810 | // Explicit line break 811 | $this->Cell($w,$h,substr($s,$j,$i-$j),0,2,'',0,$link); 812 | $i++; 813 | $sep = -1; 814 | $j = $i; 815 | $l = 0; 816 | if($nl==1) 817 | { 818 | $this->x = $this->lMargin; 819 | $w = $this->w-$this->rMargin-$this->x; 820 | $wmax = ($w-2*$this->cMargin)*1000/$this->FontSize; 821 | } 822 | $nl++; 823 | continue; 824 | } 825 | if($c==' ') 826 | $sep = $i; 827 | $l += $cw[$c]; 828 | if($l>$wmax) 829 | { 830 | // Automatic line break 831 | if($sep==-1) 832 | { 833 | if($this->x>$this->lMargin) 834 | { 835 | // Move to next line 836 | $this->x = $this->lMargin; 837 | $this->y += $h; 838 | $w = $this->w-$this->rMargin-$this->x; 839 | $wmax = ($w-2*$this->cMargin)*1000/$this->FontSize; 840 | $i++; 841 | $nl++; 842 | continue; 843 | } 844 | if($i==$j) 845 | $i++; 846 | $this->Cell($w,$h,substr($s,$j,$i-$j),0,2,'',0,$link); 847 | } 848 | else 849 | { 850 | $this->Cell($w,$h,substr($s,$j,$sep-$j),0,2,'',0,$link); 851 | $i = $sep+1; 852 | } 853 | $sep = -1; 854 | $j = $i; 855 | $l = 0; 856 | if($nl==1) 857 | { 858 | $this->x = $this->lMargin; 859 | $w = $this->w-$this->rMargin-$this->x; 860 | $wmax = ($w-2*$this->cMargin)*1000/$this->FontSize; 861 | } 862 | $nl++; 863 | } 864 | else 865 | $i++; 866 | } 867 | // Last chunk 868 | if($i!=$j) 869 | $this->Cell($l/1000*$this->FontSize,$h,substr($s,$j),0,0,'',0,$link); 870 | } 871 | 872 | function Ln($h=null) 873 | { 874 | // Line feed; default value is last cell height 875 | $this->x = $this->lMargin; 876 | if($h===null) 877 | $this->y += $this->lasth; 878 | else 879 | $this->y += $h; 880 | } 881 | 882 | function Image($file, $x=null, $y=null, $w=0, $h=0, $type='', $link='') 883 | { 884 | // Put an image on the page 885 | if(!isset($this->images[$file])) 886 | { 887 | // First use of this image, get info 888 | if($type=='') 889 | { 890 | $pos = strrpos($file,'.'); 891 | if(!$pos) 892 | $this->Error('Image file has no extension and no type was specified: '.$file); 893 | $type = substr($file,$pos+1); 894 | } 895 | $type = strtolower($type); 896 | if($type=='jpeg') 897 | $type = 'jpg'; 898 | $mtd = '_parse'.$type; 899 | if(!method_exists($this,$mtd)) 900 | $this->Error('Unsupported image type: '.$type); 901 | $info = $this->$mtd($file); 902 | $info['i'] = count($this->images)+1; 903 | $this->images[$file] = $info; 904 | } 905 | else 906 | $info = $this->images[$file]; 907 | 908 | // Automatic width and height calculation if needed 909 | if($w==0 && $h==0) 910 | { 911 | // Put image at 96 dpi 912 | $w = -96; 913 | $h = -96; 914 | } 915 | if($w<0) 916 | $w = -$info['w']*72/$w/$this->k; 917 | if($h<0) 918 | $h = -$info['h']*72/$h/$this->k; 919 | if($w==0) 920 | $w = $h*$info['w']/$info['h']; 921 | if($h==0) 922 | $h = $w*$info['h']/$info['w']; 923 | 924 | // Flowing mode 925 | if($y===null) 926 | { 927 | if($this->y+$h>$this->PageBreakTrigger && !$this->InHeader && !$this->InFooter && $this->AcceptPageBreak()) 928 | { 929 | // Automatic page break 930 | $x2 = $this->x; 931 | $this->AddPage($this->CurOrientation,$this->CurPageSize); 932 | $this->x = $x2; 933 | } 934 | $y = $this->y; 935 | $this->y += $h; 936 | } 937 | 938 | if($x===null) 939 | $x = $this->x; 940 | $this->_out(sprintf('q %.2F 0 0 %.2F %.2F %.2F cm /I%d Do Q',$w*$this->k,$h*$this->k,$x*$this->k,($this->h-($y+$h))*$this->k,$info['i'])); 941 | if($link) 942 | $this->Link($x,$y,$w,$h,$link); 943 | } 944 | 945 | function GetX() 946 | { 947 | // Get x position 948 | return $this->x; 949 | } 950 | 951 | function SetX($x) 952 | { 953 | // Set x position 954 | if($x>=0) 955 | $this->x = $x; 956 | else 957 | $this->x = $this->w+$x; 958 | } 959 | 960 | function GetY() 961 | { 962 | // Get y position 963 | return $this->y; 964 | } 965 | 966 | function SetY($y) 967 | { 968 | // Set y position and reset x 969 | $this->x = $this->lMargin; 970 | if($y>=0) 971 | $this->y = $y; 972 | else 973 | $this->y = $this->h+$y; 974 | } 975 | 976 | function SetXY($x, $y) 977 | { 978 | // Set x and y positions 979 | $this->SetY($y); 980 | $this->SetX($x); 981 | } 982 | 983 | function Output($name='', $dest='') 984 | { 985 | // Output PDF to some destination 986 | if($this->state<3) 987 | $this->Close(); 988 | $dest = strtoupper($dest); 989 | if($dest=='') 990 | { 991 | if($name=='') 992 | { 993 | $name = 'doc.pdf'; 994 | $dest = 'I'; 995 | } 996 | else 997 | $dest = 'F'; 998 | } 999 | switch($dest) 1000 | { 1001 | case 'I': 1002 | // Send to standard output 1003 | $this->_checkoutput(); 1004 | if(PHP_SAPI!='cli') 1005 | { 1006 | // We send to a browser 1007 | header('Content-Type: application/pdf'); 1008 | header('Content-Disposition: inline; filename="'.$name.'"'); 1009 | header('Cache-Control: private, max-age=0, must-revalidate'); 1010 | header('Pragma: public'); 1011 | } 1012 | echo $this->buffer; 1013 | break; 1014 | case 'D': 1015 | // Download file 1016 | $this->_checkoutput(); 1017 | header('Content-Type: application/x-download'); 1018 | header('Content-Disposition: attachment; filename="'.$name.'"'); 1019 | header('Cache-Control: private, max-age=0, must-revalidate'); 1020 | header('Pragma: public'); 1021 | echo $this->buffer; 1022 | break; 1023 | case 'F': 1024 | // Save to local file 1025 | $f = fopen($name,'wb'); 1026 | if(!$f) 1027 | $this->Error('Unable to create output file: '.$name); 1028 | fwrite($f,$this->buffer,strlen($this->buffer)); 1029 | fclose($f); 1030 | break; 1031 | case 'S': 1032 | // Return as a string 1033 | return $this->buffer; 1034 | default: 1035 | $this->Error('Incorrect output destination: '.$dest); 1036 | } 1037 | return ''; 1038 | } 1039 | 1040 | /******************************************************************************* 1041 | * * 1042 | * Protected methods * 1043 | * * 1044 | *******************************************************************************/ 1045 | function _dochecks() 1046 | { 1047 | // Check availability of %F 1048 | if(sprintf('%.1F',1.0)!='1.0') 1049 | $this->Error('This version of PHP is not supported'); 1050 | // Check mbstring overloading 1051 | if(ini_get('mbstring.func_overload') & 2) 1052 | $this->Error('mbstring overloading must be disabled'); 1053 | // Ensure runtime magic quotes are disabled 1054 | if(get_magic_quotes_runtime()) 1055 | @set_magic_quotes_runtime(0); 1056 | } 1057 | 1058 | function _checkoutput() 1059 | { 1060 | if(PHP_SAPI!='cli') 1061 | { 1062 | if(headers_sent($file,$line)) 1063 | $this->Error("Some data has already been output, can't send PDF file (output started at $file:$line)"); 1064 | } 1065 | if(ob_get_length()) 1066 | { 1067 | // The output buffer is not empty 1068 | if(preg_match('/^(\xEF\xBB\xBF)?\s*$/',ob_get_contents())) 1069 | { 1070 | // It contains only a UTF-8 BOM and/or whitespace, let's clean it 1071 | ob_clean(); 1072 | } 1073 | else 1074 | $this->Error("Some data has already been output, can't send PDF file"); 1075 | } 1076 | } 1077 | 1078 | function _getpagesize($size) 1079 | { 1080 | if(is_string($size)) 1081 | { 1082 | $size = strtolower($size); 1083 | if(!isset($this->StdPageSizes[$size])) 1084 | $this->Error('Unknown page size: '.$size); 1085 | $a = $this->StdPageSizes[$size]; 1086 | return array($a[0]/$this->k, $a[1]/$this->k); 1087 | } 1088 | else 1089 | { 1090 | if($size[0]>$size[1]) 1091 | return array($size[1], $size[0]); 1092 | else 1093 | return $size; 1094 | } 1095 | } 1096 | 1097 | function _beginpage($orientation, $size) 1098 | { 1099 | $this->page++; 1100 | $this->pages[$this->page] = ''; 1101 | $this->state = 2; 1102 | $this->x = $this->lMargin; 1103 | $this->y = $this->tMargin; 1104 | $this->FontFamily = ''; 1105 | // Check page size and orientation 1106 | if($orientation=='') 1107 | $orientation = $this->DefOrientation; 1108 | else 1109 | $orientation = strtoupper($orientation[0]); 1110 | if($size=='') 1111 | $size = $this->DefPageSize; 1112 | else 1113 | $size = $this->_getpagesize($size); 1114 | if($orientation!=$this->CurOrientation || $size[0]!=$this->CurPageSize[0] || $size[1]!=$this->CurPageSize[1]) 1115 | { 1116 | // New size or orientation 1117 | if($orientation=='P') 1118 | { 1119 | $this->w = $size[0]; 1120 | $this->h = $size[1]; 1121 | } 1122 | else 1123 | { 1124 | $this->w = $size[1]; 1125 | $this->h = $size[0]; 1126 | } 1127 | $this->wPt = $this->w*$this->k; 1128 | $this->hPt = $this->h*$this->k; 1129 | $this->PageBreakTrigger = $this->h-$this->bMargin; 1130 | $this->CurOrientation = $orientation; 1131 | $this->CurPageSize = $size; 1132 | } 1133 | if($orientation!=$this->DefOrientation || $size[0]!=$this->DefPageSize[0] || $size[1]!=$this->DefPageSize[1]) 1134 | $this->PageSizes[$this->page] = array($this->wPt, $this->hPt); 1135 | } 1136 | 1137 | function _endpage() 1138 | { 1139 | $this->state = 1; 1140 | } 1141 | 1142 | function _loadfont($font) 1143 | { 1144 | // Load a font definition file from the font directory 1145 | include($this->fontpath.$font); 1146 | $a = get_defined_vars(); 1147 | if(!isset($a['name'])) 1148 | $this->Error('Could not include font definition file'); 1149 | return $a; 1150 | } 1151 | 1152 | function _escape($s) 1153 | { 1154 | // Escape special characters in strings 1155 | $s = str_replace('\\','\\\\',$s); 1156 | $s = str_replace('(','\\(',$s); 1157 | $s = str_replace(')','\\)',$s); 1158 | $s = str_replace("\r",'\\r',$s); 1159 | return $s; 1160 | } 1161 | 1162 | function _textstring($s) 1163 | { 1164 | // Format a text string 1165 | return '('.$this->_escape($s).')'; 1166 | } 1167 | 1168 | function _UTF8toUTF16($s) 1169 | { 1170 | // Convert UTF-8 to UTF-16BE with BOM 1171 | $res = "\xFE\xFF"; 1172 | $nb = strlen($s); 1173 | $i = 0; 1174 | while($i<$nb) 1175 | { 1176 | $c1 = ord($s[$i++]); 1177 | if($c1>=224) 1178 | { 1179 | // 3-byte character 1180 | $c2 = ord($s[$i++]); 1181 | $c3 = ord($s[$i++]); 1182 | $res .= chr((($c1 & 0x0F)<<4) + (($c2 & 0x3C)>>2)); 1183 | $res .= chr((($c2 & 0x03)<<6) + ($c3 & 0x3F)); 1184 | } 1185 | elseif($c1>=192) 1186 | { 1187 | // 2-byte character 1188 | $c2 = ord($s[$i++]); 1189 | $res .= chr(($c1 & 0x1C)>>2); 1190 | $res .= chr((($c1 & 0x03)<<6) + ($c2 & 0x3F)); 1191 | } 1192 | else 1193 | { 1194 | // Single-byte character 1195 | $res .= "\0".chr($c1); 1196 | } 1197 | } 1198 | return $res; 1199 | } 1200 | 1201 | function _dounderline($x, $y, $txt) 1202 | { 1203 | // Underline text 1204 | $up = $this->CurrentFont['up']; 1205 | $ut = $this->CurrentFont['ut']; 1206 | $w = $this->GetStringWidth($txt)+$this->ws*substr_count($txt,' '); 1207 | return sprintf('%.2F %.2F %.2F %.2F re f',$x*$this->k,($this->h-($y-$up/1000*$this->FontSize))*$this->k,$w*$this->k,-$ut/1000*$this->FontSizePt); 1208 | } 1209 | 1210 | function _parsejpg($file) 1211 | { 1212 | // Extract info from a JPEG file 1213 | $a = getimagesize($file); 1214 | if(!$a) 1215 | $this->Error('Missing or incorrect image file: '.$file); 1216 | if($a[2]!=2) 1217 | $this->Error('Not a JPEG file: '.$file); 1218 | if(!isset($a['channels']) || $a['channels']==3) 1219 | $colspace = 'DeviceRGB'; 1220 | elseif($a['channels']==4) 1221 | $colspace = 'DeviceCMYK'; 1222 | else 1223 | $colspace = 'DeviceGray'; 1224 | $bpc = isset($a['bits']) ? $a['bits'] : 8; 1225 | $data = file_get_contents($file); 1226 | return array('w'=>$a[0], 'h'=>$a[1], 'cs'=>$colspace, 'bpc'=>$bpc, 'f'=>'DCTDecode', 'data'=>$data); 1227 | } 1228 | 1229 | function _parsepng($file) 1230 | { 1231 | // Extract info from a PNG file 1232 | $f = fopen($file,'rb'); 1233 | if(!$f) 1234 | $this->Error('Can\'t open image file: '.$file); 1235 | $info = $this->_parsepngstream($f,$file); 1236 | fclose($f); 1237 | return $info; 1238 | } 1239 | 1240 | function _parsepngstream($f, $file) 1241 | { 1242 | // Check signature 1243 | if($this->_readstream($f,8)!=chr(137).'PNG'.chr(13).chr(10).chr(26).chr(10)) 1244 | $this->Error('Not a PNG file: '.$file); 1245 | 1246 | // Read header chunk 1247 | $this->_readstream($f,4); 1248 | if($this->_readstream($f,4)!='IHDR') 1249 | $this->Error('Incorrect PNG file: '.$file); 1250 | $w = $this->_readint($f); 1251 | $h = $this->_readint($f); 1252 | $bpc = ord($this->_readstream($f,1)); 1253 | if($bpc>8) 1254 | $this->Error('16-bit depth not supported: '.$file); 1255 | $ct = ord($this->_readstream($f,1)); 1256 | if($ct==0 || $ct==4) 1257 | $colspace = 'DeviceGray'; 1258 | elseif($ct==2 || $ct==6) 1259 | $colspace = 'DeviceRGB'; 1260 | elseif($ct==3) 1261 | $colspace = 'Indexed'; 1262 | else 1263 | $this->Error('Unknown color type: '.$file); 1264 | if(ord($this->_readstream($f,1))!=0) 1265 | $this->Error('Unknown compression method: '.$file); 1266 | if(ord($this->_readstream($f,1))!=0) 1267 | $this->Error('Unknown filter method: '.$file); 1268 | if(ord($this->_readstream($f,1))!=0) 1269 | $this->Error('Interlacing not supported: '.$file); 1270 | $this->_readstream($f,4); 1271 | $dp = '/Predictor 15 /Colors '.($colspace=='DeviceRGB' ? 3 : 1).' /BitsPerComponent '.$bpc.' /Columns '.$w; 1272 | 1273 | // Scan chunks looking for palette, transparency and image data 1274 | $pal = ''; 1275 | $trns = ''; 1276 | $data = ''; 1277 | do 1278 | { 1279 | $n = $this->_readint($f); 1280 | $type = $this->_readstream($f,4); 1281 | if($type=='PLTE') 1282 | { 1283 | // Read palette 1284 | $pal = $this->_readstream($f,$n); 1285 | $this->_readstream($f,4); 1286 | } 1287 | elseif($type=='tRNS') 1288 | { 1289 | // Read transparency info 1290 | $t = $this->_readstream($f,$n); 1291 | if($ct==0) 1292 | $trns = array(ord(substr($t,1,1))); 1293 | elseif($ct==2) 1294 | $trns = array(ord(substr($t,1,1)), ord(substr($t,3,1)), ord(substr($t,5,1))); 1295 | else 1296 | { 1297 | $pos = strpos($t,chr(0)); 1298 | if($pos!==false) 1299 | $trns = array($pos); 1300 | } 1301 | $this->_readstream($f,4); 1302 | } 1303 | elseif($type=='IDAT') 1304 | { 1305 | // Read image data block 1306 | $data .= $this->_readstream($f,$n); 1307 | $this->_readstream($f,4); 1308 | } 1309 | elseif($type=='IEND') 1310 | break; 1311 | else 1312 | $this->_readstream($f,$n+4); 1313 | } 1314 | while($n); 1315 | 1316 | if($colspace=='Indexed' && empty($pal)) 1317 | $this->Error('Missing palette in '.$file); 1318 | $info = array('w'=>$w, 'h'=>$h, 'cs'=>$colspace, 'bpc'=>$bpc, 'f'=>'FlateDecode', 'dp'=>$dp, 'pal'=>$pal, 'trns'=>$trns); 1319 | if($ct>=4) 1320 | { 1321 | // Extract alpha channel 1322 | if(!function_exists('gzuncompress')) 1323 | $this->Error('Zlib not available, can\'t handle alpha channel: '.$file); 1324 | $data = gzuncompress($data); 1325 | $color = ''; 1326 | $alpha = ''; 1327 | if($ct==4) 1328 | { 1329 | // Gray image 1330 | $len = 2*$w; 1331 | for($i=0;$i<$h;$i++) 1332 | { 1333 | $pos = (1+$len)*$i; 1334 | $color .= $data[$pos]; 1335 | $alpha .= $data[$pos]; 1336 | $line = substr($data,$pos+1,$len); 1337 | $color .= preg_replace('/(.)./s','$1',$line); 1338 | $alpha .= preg_replace('/.(.)/s','$1',$line); 1339 | } 1340 | } 1341 | else 1342 | { 1343 | // RGB image 1344 | $len = 4*$w; 1345 | for($i=0;$i<$h;$i++) 1346 | { 1347 | $pos = (1+$len)*$i; 1348 | $color .= $data[$pos]; 1349 | $alpha .= $data[$pos]; 1350 | $line = substr($data,$pos+1,$len); 1351 | $color .= preg_replace('/(.{3})./s','$1',$line); 1352 | $alpha .= preg_replace('/.{3}(.)/s','$1',$line); 1353 | } 1354 | } 1355 | unset($data); 1356 | $data = gzcompress($color); 1357 | $info['smask'] = gzcompress($alpha); 1358 | if($this->PDFVersion<'1.4') 1359 | $this->PDFVersion = '1.4'; 1360 | } 1361 | $info['data'] = $data; 1362 | return $info; 1363 | } 1364 | 1365 | function _readstream($f, $n) 1366 | { 1367 | // Read n bytes from stream 1368 | $res = ''; 1369 | while($n>0 && !feof($f)) 1370 | { 1371 | $s = fread($f,$n); 1372 | if($s===false) 1373 | $this->Error('Error while reading stream'); 1374 | $n -= strlen($s); 1375 | $res .= $s; 1376 | } 1377 | if($n>0) 1378 | $this->Error('Unexpected end of stream'); 1379 | return $res; 1380 | } 1381 | 1382 | function _readint($f) 1383 | { 1384 | // Read a 4-byte integer from stream 1385 | $a = unpack('Ni',$this->_readstream($f,4)); 1386 | return $a['i']; 1387 | } 1388 | 1389 | function _parsegif($file) 1390 | { 1391 | // Extract info from a GIF file (via PNG conversion) 1392 | if(!function_exists('imagepng')) 1393 | $this->Error('GD extension is required for GIF support'); 1394 | if(!function_exists('imagecreatefromgif')) 1395 | $this->Error('GD has no GIF read support'); 1396 | $im = imagecreatefromgif($file); 1397 | if(!$im) 1398 | $this->Error('Missing or incorrect image file: '.$file); 1399 | imageinterlace($im,0); 1400 | $f = @fopen('php://temp','rb+'); 1401 | if($f) 1402 | { 1403 | // Perform conversion in memory 1404 | ob_start(); 1405 | imagepng($im); 1406 | $data = ob_get_clean(); 1407 | imagedestroy($im); 1408 | fwrite($f,$data); 1409 | rewind($f); 1410 | $info = $this->_parsepngstream($f,$file); 1411 | fclose($f); 1412 | } 1413 | else 1414 | { 1415 | // Use temporary file 1416 | $tmp = tempnam('.','gif'); 1417 | if(!$tmp) 1418 | $this->Error('Unable to create a temporary file'); 1419 | if(!imagepng($im,$tmp)) 1420 | $this->Error('Error while saving to temporary file'); 1421 | imagedestroy($im); 1422 | $info = $this->_parsepng($tmp); 1423 | unlink($tmp); 1424 | } 1425 | return $info; 1426 | } 1427 | 1428 | function _newobj() 1429 | { 1430 | // Begin a new object 1431 | $this->n++; 1432 | $this->offsets[$this->n] = strlen($this->buffer); 1433 | $this->_out($this->n.' 0 obj'); 1434 | } 1435 | 1436 | function _putstream($s) 1437 | { 1438 | $this->_out('stream'); 1439 | $this->_out($s); 1440 | $this->_out('endstream'); 1441 | } 1442 | 1443 | function _out($s) 1444 | { 1445 | // Add a line to the document 1446 | if($this->state==2) 1447 | $this->pages[$this->page] .= $s."\n"; 1448 | else 1449 | $this->buffer .= $s."\n"; 1450 | } 1451 | 1452 | function _putpages() 1453 | { 1454 | $nb = $this->page; 1455 | if(!empty($this->AliasNbPages)) 1456 | { 1457 | // Replace number of pages 1458 | for($n=1;$n<=$nb;$n++) 1459 | $this->pages[$n] = str_replace($this->AliasNbPages,$nb,$this->pages[$n]); 1460 | } 1461 | if($this->DefOrientation=='P') 1462 | { 1463 | $wPt = $this->DefPageSize[0]*$this->k; 1464 | $hPt = $this->DefPageSize[1]*$this->k; 1465 | } 1466 | else 1467 | { 1468 | $wPt = $this->DefPageSize[1]*$this->k; 1469 | $hPt = $this->DefPageSize[0]*$this->k; 1470 | } 1471 | $filter = ($this->compress) ? '/Filter /FlateDecode ' : ''; 1472 | for($n=1;$n<=$nb;$n++) 1473 | { 1474 | // Page 1475 | $this->_newobj(); 1476 | $this->_out('<_out('/Parent 1 0 R'); 1478 | if(isset($this->PageSizes[$n])) 1479 | $this->_out(sprintf('/MediaBox [0 0 %.2F %.2F]',$this->PageSizes[$n][0],$this->PageSizes[$n][1])); 1480 | $this->_out('/Resources 2 0 R'); 1481 | if(isset($this->PageLinks[$n])) 1482 | { 1483 | // Links 1484 | $annots = '/Annots ['; 1485 | foreach($this->PageLinks[$n] as $pl) 1486 | { 1487 | $rect = sprintf('%.2F %.2F %.2F %.2F',$pl[0],$pl[1],$pl[0]+$pl[2],$pl[1]-$pl[3]); 1488 | $annots .= '<_textstring($pl[4]).'>>>>'; 1491 | else 1492 | { 1493 | $l = $this->links[$pl[4]]; 1494 | $h = isset($this->PageSizes[$l[0]]) ? $this->PageSizes[$l[0]][1] : $hPt; 1495 | $annots .= sprintf('/Dest [%d 0 R /XYZ 0 %.2F null]>>',1+2*$l[0],$h-$l[1]*$this->k); 1496 | } 1497 | } 1498 | $this->_out($annots.']'); 1499 | } 1500 | if($this->PDFVersion>'1.3') 1501 | $this->_out('/Group <>'); 1502 | $this->_out('/Contents '.($this->n+1).' 0 R>>'); 1503 | $this->_out('endobj'); 1504 | // Page content 1505 | $p = ($this->compress) ? gzcompress($this->pages[$n]) : $this->pages[$n]; 1506 | $this->_newobj(); 1507 | $this->_out('<<'.$filter.'/Length '.strlen($p).'>>'); 1508 | $this->_putstream($p); 1509 | $this->_out('endobj'); 1510 | } 1511 | // Pages root 1512 | $this->offsets[1] = strlen($this->buffer); 1513 | $this->_out('1 0 obj'); 1514 | $this->_out('<_out($kids.']'); 1519 | $this->_out('/Count '.$nb); 1520 | $this->_out(sprintf('/MediaBox [0 0 %.2F %.2F]',$wPt,$hPt)); 1521 | $this->_out('>>'); 1522 | $this->_out('endobj'); 1523 | } 1524 | 1525 | function _putfonts() 1526 | { 1527 | $nf = $this->n; 1528 | foreach($this->diffs as $diff) 1529 | { 1530 | // Encodings 1531 | $this->_newobj(); 1532 | $this->_out('<>'); 1533 | $this->_out('endobj'); 1534 | } 1535 | foreach($this->FontFiles as $file=>$info) 1536 | { 1537 | // Font file embedding 1538 | $this->_newobj(); 1539 | $this->FontFiles[$file]['n'] = $this->n; 1540 | $font = file_get_contents($this->fontpath.$file,true); 1541 | if(!$font) 1542 | $this->Error('Font file not found: '.$file); 1543 | $compressed = (substr($file,-2)=='.z'); 1544 | if(!$compressed && isset($info['length2'])) 1545 | $font = substr($font,6,$info['length1']).substr($font,6+$info['length1']+6,$info['length2']); 1546 | $this->_out('<_out('/Filter /FlateDecode'); 1549 | $this->_out('/Length1 '.$info['length1']); 1550 | if(isset($info['length2'])) 1551 | $this->_out('/Length2 '.$info['length2'].' /Length3 0'); 1552 | $this->_out('>>'); 1553 | $this->_putstream($font); 1554 | $this->_out('endobj'); 1555 | } 1556 | foreach($this->fonts as $k=>$font) 1557 | { 1558 | // Font objects 1559 | $this->fonts[$k]['n'] = $this->n+1; 1560 | $type = $font['type']; 1561 | $name = $font['name']; 1562 | if($type=='Core') 1563 | { 1564 | // Core font 1565 | $this->_newobj(); 1566 | $this->_out('<_out('/BaseFont /'.$name); 1568 | $this->_out('/Subtype /Type1'); 1569 | if($name!='Symbol' && $name!='ZapfDingbats') 1570 | $this->_out('/Encoding /WinAnsiEncoding'); 1571 | $this->_out('>>'); 1572 | $this->_out('endobj'); 1573 | } 1574 | elseif($type=='Type1' || $type=='TrueType') 1575 | { 1576 | // Additional Type1 or TrueType/OpenType font 1577 | $this->_newobj(); 1578 | $this->_out('<_out('/BaseFont /'.$name); 1580 | $this->_out('/Subtype /'.$type); 1581 | $this->_out('/FirstChar 32 /LastChar 255'); 1582 | $this->_out('/Widths '.($this->n+1).' 0 R'); 1583 | $this->_out('/FontDescriptor '.($this->n+2).' 0 R'); 1584 | if(isset($font['diffn'])) 1585 | $this->_out('/Encoding '.($nf+$font['diffn']).' 0 R'); 1586 | else 1587 | $this->_out('/Encoding /WinAnsiEncoding'); 1588 | $this->_out('>>'); 1589 | $this->_out('endobj'); 1590 | // Widths 1591 | $this->_newobj(); 1592 | $cw = &$font['cw']; 1593 | $s = '['; 1594 | for($i=32;$i<=255;$i++) 1595 | $s .= $cw[chr($i)].' '; 1596 | $this->_out($s.']'); 1597 | $this->_out('endobj'); 1598 | // Descriptor 1599 | $this->_newobj(); 1600 | $s = '<$v) 1602 | $s .= ' /'.$k.' '.$v; 1603 | if(!empty($font['file'])) 1604 | $s .= ' /FontFile'.($type=='Type1' ? '' : '2').' '.$this->FontFiles[$font['file']]['n'].' 0 R'; 1605 | $this->_out($s.'>>'); 1606 | $this->_out('endobj'); 1607 | } 1608 | else 1609 | { 1610 | // Allow for additional types 1611 | $mtd = '_put'.strtolower($type); 1612 | if(!method_exists($this,$mtd)) 1613 | $this->Error('Unsupported font type: '.$type); 1614 | $this->$mtd($font); 1615 | } 1616 | } 1617 | } 1618 | 1619 | function _putimages() 1620 | { 1621 | foreach(array_keys($this->images) as $file) 1622 | { 1623 | $this->_putimage($this->images[$file]); 1624 | unset($this->images[$file]['data']); 1625 | unset($this->images[$file]['smask']); 1626 | } 1627 | } 1628 | 1629 | function _putimage(&$info) 1630 | { 1631 | $this->_newobj(); 1632 | $info['n'] = $this->n; 1633 | $this->_out('<_out('/Subtype /Image'); 1635 | $this->_out('/Width '.$info['w']); 1636 | $this->_out('/Height '.$info['h']); 1637 | if($info['cs']=='Indexed') 1638 | $this->_out('/ColorSpace [/Indexed /DeviceRGB '.(strlen($info['pal'])/3-1).' '.($this->n+1).' 0 R]'); 1639 | else 1640 | { 1641 | $this->_out('/ColorSpace /'.$info['cs']); 1642 | if($info['cs']=='DeviceCMYK') 1643 | $this->_out('/Decode [1 0 1 0 1 0 1 0]'); 1644 | } 1645 | $this->_out('/BitsPerComponent '.$info['bpc']); 1646 | if(isset($info['f'])) 1647 | $this->_out('/Filter /'.$info['f']); 1648 | if(isset($info['dp'])) 1649 | $this->_out('/DecodeParms <<'.$info['dp'].'>>'); 1650 | if(isset($info['trns']) && is_array($info['trns'])) 1651 | { 1652 | $trns = ''; 1653 | for($i=0;$i_out('/Mask ['.$trns.']'); 1656 | } 1657 | if(isset($info['smask'])) 1658 | $this->_out('/SMask '.($this->n+1).' 0 R'); 1659 | $this->_out('/Length '.strlen($info['data']).'>>'); 1660 | $this->_putstream($info['data']); 1661 | $this->_out('endobj'); 1662 | // Soft mask 1663 | if(isset($info['smask'])) 1664 | { 1665 | $dp = '/Predictor 15 /Colors 1 /BitsPerComponent 8 /Columns '.$info['w']; 1666 | $smask = array('w'=>$info['w'], 'h'=>$info['h'], 'cs'=>'DeviceGray', 'bpc'=>8, 'f'=>$info['f'], 'dp'=>$dp, 'data'=>$info['smask']); 1667 | $this->_putimage($smask); 1668 | } 1669 | // Palette 1670 | if($info['cs']=='Indexed') 1671 | { 1672 | $filter = ($this->compress) ? '/Filter /FlateDecode ' : ''; 1673 | $pal = ($this->compress) ? gzcompress($info['pal']) : $info['pal']; 1674 | $this->_newobj(); 1675 | $this->_out('<<'.$filter.'/Length '.strlen($pal).'>>'); 1676 | $this->_putstream($pal); 1677 | $this->_out('endobj'); 1678 | } 1679 | } 1680 | 1681 | function _putxobjectdict() 1682 | { 1683 | foreach($this->images as $image) 1684 | $this->_out('/I'.$image['i'].' '.$image['n'].' 0 R'); 1685 | } 1686 | 1687 | function _putresourcedict() 1688 | { 1689 | $this->_out('/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]'); 1690 | $this->_out('/Font <<'); 1691 | foreach($this->fonts as $font) 1692 | $this->_out('/F'.$font['i'].' '.$font['n'].' 0 R'); 1693 | $this->_out('>>'); 1694 | $this->_out('/XObject <<'); 1695 | $this->_putxobjectdict(); 1696 | $this->_out('>>'); 1697 | } 1698 | 1699 | function _putresources() 1700 | { 1701 | $this->_putfonts(); 1702 | $this->_putimages(); 1703 | // Resource dictionary 1704 | $this->offsets[2] = strlen($this->buffer); 1705 | $this->_out('2 0 obj'); 1706 | $this->_out('<<'); 1707 | $this->_putresourcedict(); 1708 | $this->_out('>>'); 1709 | $this->_out('endobj'); 1710 | } 1711 | 1712 | function _putinfo() 1713 | { 1714 | $this->_out('/Producer '.$this->_textstring('FPDF '.FPDF_VERSION)); 1715 | if(!empty($this->title)) 1716 | $this->_out('/Title '.$this->_textstring($this->title)); 1717 | if(!empty($this->subject)) 1718 | $this->_out('/Subject '.$this->_textstring($this->subject)); 1719 | if(!empty($this->author)) 1720 | $this->_out('/Author '.$this->_textstring($this->author)); 1721 | if(!empty($this->keywords)) 1722 | $this->_out('/Keywords '.$this->_textstring($this->keywords)); 1723 | if(!empty($this->creator)) 1724 | $this->_out('/Creator '.$this->_textstring($this->creator)); 1725 | $this->_out('/CreationDate '.$this->_textstring('D:'.@date('YmdHis'))); 1726 | } 1727 | 1728 | function _putcatalog() 1729 | { 1730 | $this->_out('/Type /Catalog'); 1731 | $this->_out('/Pages 1 0 R'); 1732 | if($this->ZoomMode=='fullpage') 1733 | $this->_out('/OpenAction [3 0 R /Fit]'); 1734 | elseif($this->ZoomMode=='fullwidth') 1735 | $this->_out('/OpenAction [3 0 R /FitH null]'); 1736 | elseif($this->ZoomMode=='real') 1737 | $this->_out('/OpenAction [3 0 R /XYZ null null 1]'); 1738 | elseif(!is_string($this->ZoomMode)) 1739 | $this->_out('/OpenAction [3 0 R /XYZ null null '.sprintf('%.2F',$this->ZoomMode/100).']'); 1740 | if($this->LayoutMode=='single') 1741 | $this->_out('/PageLayout /SinglePage'); 1742 | elseif($this->LayoutMode=='continuous') 1743 | $this->_out('/PageLayout /OneColumn'); 1744 | elseif($this->LayoutMode=='two') 1745 | $this->_out('/PageLayout /TwoColumnLeft'); 1746 | } 1747 | 1748 | function _putheader() 1749 | { 1750 | $this->_out('%PDF-'.$this->PDFVersion); 1751 | } 1752 | 1753 | function _puttrailer() 1754 | { 1755 | $this->_out('/Size '.($this->n+1)); 1756 | $this->_out('/Root '.$this->n.' 0 R'); 1757 | $this->_out('/Info '.($this->n-1).' 0 R'); 1758 | } 1759 | 1760 | function _enddoc() 1761 | { 1762 | $this->_putheader(); 1763 | $this->_putpages(); 1764 | $this->_putresources(); 1765 | // Info 1766 | $this->_newobj(); 1767 | $this->_out('<<'); 1768 | $this->_putinfo(); 1769 | $this->_out('>>'); 1770 | $this->_out('endobj'); 1771 | // Catalog 1772 | $this->_newobj(); 1773 | $this->_out('<<'); 1774 | $this->_putcatalog(); 1775 | $this->_out('>>'); 1776 | $this->_out('endobj'); 1777 | // Cross-ref 1778 | $o = strlen($this->buffer); 1779 | $this->_out('xref'); 1780 | $this->_out('0 '.($this->n+1)); 1781 | $this->_out('0000000000 65535 f '); 1782 | for($i=1;$i<=$this->n;$i++) 1783 | $this->_out(sprintf('%010d 00000 n ',$this->offsets[$i])); 1784 | // Trailer 1785 | $this->_out('trailer'); 1786 | $this->_out('<<'); 1787 | $this->_puttrailer(); 1788 | $this->_out('>>'); 1789 | $this->_out('startxref'); 1790 | $this->_out($o); 1791 | $this->_out('%%EOF'); 1792 | $this->state = 3; 1793 | } 1794 | // End of class 1795 | } 1796 | 1797 | // Handle special IE contype request 1798 | if(isset($_SERVER['HTTP_USER_AGENT']) && $_SERVER['HTTP_USER_AGENT']=='contype') 1799 | { 1800 | header('Content-Type: application/pdf'); 1801 | exit; 1802 | } 1803 | 1804 | ?> 1805 | --------------------------------------------------------------------------------