Changeset 373 for trunk/Common/Global.php
- Timestamp:
- Jan 19, 2012, 9:43:36 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Common/Global.php
r372 r373 8 8 include_once('Database.php'); 9 9 include_once('Error.php'); 10 include_once(' Code.php');10 include_once('UTF8.php'); 11 11 include_once('File.php'); 12 12 include_once('Page.php'); 13 include_once('Mail.php'); 14 include_once('PrefixMultiplier.php'); 13 15 include_once('Module.php'); 14 16 include_once('Model.php'); 17 include_once('XML.php'); 18 include_once('HTML.php'); 19 include_once('XHTML.php'); 20 include_once('PageList.php'); 21 include_once('TableHeader.php'); 15 22 include_once('View.php'); 16 17 $PrefixMultipliers = array 18 ( 19 'Binary' => array 20 ( 21 'BaseIndex' => 0, 22 'Definition' => array 23 ( 24 array('', '', pow(2, 0)), 25 array('Ki', 'kibi', pow(2, 10)), 26 array('Mi', 'mebi', pow(2, 20)), 27 array('Gi', 'gibi', pow(2, 30)), 28 array('Ti', 'tebi', pow(2, 40)), 29 array('Pi', 'pebi', pow(2, 50)), 30 array('Ei', 'exbi', pow(2, 60)), 31 array('Zi', 'zebi', pow(2, 70)), 32 array('Yi', 'yobi', pow(2, 80)), 33 ), 34 ), 35 'Decimal' => array 36 ( 37 'BaseIndex' => 8, 38 'Definition' => array 39 ( 40 array('y', 'yocto', pow(10, -24)), 41 array('z', 'zepto', pow(10, -21)), 42 array('a', 'atto', pow(10, -18)), 43 array('f', 'femto', pow(10, -15)), 44 array('p', 'piko', pow(10, -12)), 45 array('n', 'nano', pow(10, -9)), 46 array('u', 'mikro', pow(10, -6)), 47 array('m', 'mili', pow(10, -3)), 48 array('', '', pow(10, 0)), 49 array('k', 'kilo', pow(10, 3)), 50 array('M', 'mega', pow(10, 6)), 51 array('G', 'giga', pow(10, 9)), 52 array('T', 'tera', pow(10, 12)), 53 array('P', 'peta', pow(10, 15)), 54 array('E', 'exa', pow(10, 18)), 55 array('Z', 'zetta', pow(10, 21)), 56 array('Y', 'yotta', pow(10, 24)), 57 ), 58 ), 59 'Time' => array 60 ( 61 'BaseIndex' => 8, 62 'Definition' => array 63 ( 64 array('ys', 'yoctosekunda', pow(10, -24)), 65 array('zs', 'zeptosekunda', pow(10, -21)), 66 array('as', 'attosekunda', pow(10, -18)), 67 array('fs', 'femtosekunda', pow(10, -15)), 68 array('ps', 'pikosekunda', pow(10, -12)), 69 array('ns', 'nanosekunda', pow(10, -9)), 70 array('us', 'mikrosekunda', pow(10, -6)), 71 array('ms', 'milisekunda', pow(10, -3)), 72 array('s', 'sekunda', 1), 73 array('minut', 'minuta', 60), 74 array('hodin', 'hodina', 60 * 60) , 75 array('dnů', 'den', 24 * 60 * 60), 76 array('týdnů', 'týden', 7 * 24 * 60 * 60), 77 array('měsíců', 'měsíc', 30 * 24 * 60 * 60), 78 array('roků', 'rok', 364 * 24 * 60 * 60), 79 array('desetiletí', 'desetiletí', 10 * 364 * 24 * 60 * 60), 80 array('stalatí', 'staletí', 100 * 364 * 24 * 60 * 60), 81 array('tisíciletí', 'tisiciletí', 10000 * 364 * 24 * 60 * 60), 82 ), 83 ), 84 ); 23 include_once('ViewList.php'); 24 include_once('ViewForm.php'); 25 85 26 86 27 class System extends ModularSystem … … 88 29 var $Pages = array(); 89 30 90 function AddModule($Module)91 {92 global $Database;93 94 //echo('Přidávám modul '.get_class($Module).'<br />');95 $Module->System = &$this;96 $Module->Database = &$Database;97 $this->Modules[get_class($Module)] = $Module;98 }99 100 function AddEmailToQueue($Address, $Subject, $Content, $Headers = '')101 {102 $this->Database->insert('EmailQueue', array('Address' => $Address, 'Subject' => $Subject, 'Content' => $Content, 'Time' => 'NOW()', 'Headers' => $Headers));103 }104 105 function MailUTF8($To, $Subject = '(No subject)', $Message = '', $Header = '')106 {107 $Header = 'MIME-Version: 1.0' . "\r\n" . 'Content-type: text/html; charset=UTF-8' . "\r\n".$Header;108 mail($To, '=?UTF-8?B?'.base64_encode($Subject).'?=', $Message, $Header);109 //echo('mail('.$To.', =?UTF-8?B?'.base64_encode($Subject).'?=, '.$Message.', '.$Header.')<br/>');110 }111 112 function ProcessEmailQueue()113 {114 $Output = '';115 $DbResult = $this->Database->select('EmailQueue', '*', 'Archive=0');116 while($DbRow = $DbResult->fetch_assoc())117 {118 $this->MailUTF8($DbRow['Address'], $DbRow['Subject'], $DbRow['Content'], $DbRow['Headers']);119 //echo('mail('.$DbRow['Address'].', '.$DbRow['Subject'].', '.$DbRow['Content'].', FromUTF8('.$DbRow['Headers'].', \'iso2\'));');120 $this->Database->update('EmailQueue', 'Id='.$DbRow['Id'], array('Archive' => 1));121 $this->Modules['Log']->NewRecord('System', 'SendEmail', $DbRow['Id']);122 $Output .= 'To: '.$DbRow['Address'].' Subject: '.$DbRow['Subject'].'<br />';123 }124 return($Output);125 }126 127 31 function HumanDate($Time) 128 32 { 129 33 return(date('j.n.Y', $Time)); 130 }131 132 function TruncateDigits($Value, $Digits = 4)133 {134 for($II = 2; $II > -6; $II--)135 {136 if($Value >= pow(10, $II))137 {138 if($Digits < ($II + 1)) $RealDigits = $II + 1; else $RealDigits = $Digits;139 $Value = round($Value / pow(10, $II - $RealDigits + 1)) * pow(10, $II - $RealDigits + 1);140 break;141 }142 }143 return($Value);144 }145 146 function AddPrefixMultipliers($Value, $Unit, $Digits = 4, $PrefixType = 'Decimal')147 {148 global $PrefixMultipliers;149 150 $Negative = ($Value < 0);151 $Value = abs($Value);152 if(($Unit == '') and ($PrefixType != 'Time'))153 return($this->TruncateDigits($Value, $Digits));154 155 $I = $PrefixMultipliers[$PrefixType]['BaseIndex'];156 if($Value == 0) return($Value.' '.$PrefixMultipliers[$PrefixType]['Definition'][$I][0].$Unit);157 158 if($Value > 1)159 {160 while((($I + 1) <= count($PrefixMultipliers[$PrefixType]['Definition'])) and (($Value / $PrefixMultipliers[$PrefixType]['Definition'][$I + 1][2]) > 1))161 $I = $I + 1;162 } else163 if($Value < 1)164 {165 while((($I - 1) >= 0) and (($Value / $PrefixMultipliers[$PrefixType]['Definition'][$I][2]) < 1))166 $I = $I - 1;167 }168 $Value = $Value / $PrefixMultipliers[$PrefixType]['Definition'][$I][2];169 170 // Truncate digits count171 $Value = $this->TruncateDigits($Value, $Digits);172 if($Negative) $Value = -$Value;173 return($Value.' '.$PrefixMultipliers[$PrefixType]['Definition'][$I][0].$Unit);174 34 } 175 35
Note:
See TracChangeset
for help on using the changeset viewer.