![]() |
|---|
| [ Index ] |
Source Code Reference for V1.00 |
[Summary view] [Print] [Text view]
1 <?php /* $Id: syskeys.class.php 56 2008-02-19 18:39:18Z pedroix $ $URL: https://web2project.svn.sourceforge.net/svnroot/web2project/trunk/modules/system/syskeys/syskeys.class.php $ */ 2 if (!defined('W2P_BASE_DIR')) { 3 die('You should not access this file directly.'); 4 } 5 6 include_once ($AppUI->getSystemClass('w2p')); 7 8 ## 9 ## CSysKey Class 10 ## 11 12 class CSysKey extends CW2pObject { 13 var $syskey_id = null; 14 var $syskey_name = null; 15 var $syskey_label = null; 16 var $syskey_type = null; 17 var $syskey_sep1 = null; 18 var $syskey_sep2 = null; 19 20 function CSysKey($name = null, $label = null, $type = '0', $sep1 = "\n", $sep2 = '|') { 21 $this->CW2pObject('syskeys', 'syskey_id'); 22 $this->syskey_name = $name; 23 $this->syskey_label = $label; 24 $this->syskey_type = $type; 25 $this->syskey_sep1 = $sep1; 26 $this->syskey_sep2 = $sep2; 27 } 28 } 29 30 ## 31 ## CSysVal Class 32 ## 33 34 class CSysVal extends CW2pObject { 35 var $sysval_id = null; 36 var $sysval_key_id = null; 37 var $sysval_title = null; 38 var $sysval_value_id = null; 39 var $sysval_value = null; 40 41 function check() { 42 //print_r($this);die; 43 if ($this->sysval_key_id == 0) { 44 return 'Key Type cannot be empty'; 45 } 46 if (!$this->sysval_title) { 47 return 'Key Title cannot be empty'; 48 } 49 return null; 50 } 51 52 function CSysVal($key = null, $title = null, $value = null) { 53 $this->CW2pObject('sysvals', 'sysval_id'); 54 $this->sysval_key_id = $key; 55 $this->sysval_title = $title; 56 $this->sysval_value = $value; 57 } 58 59 function store() { 60 $this->w2PTrimAll(); 61 62 $msg = $this->check(); 63 if ($msg) { 64 return get_class($this) . '::store-check failed - ' . $msg; 65 } 66 $values = parseFormatSysval($this->sysval_value, $this->sysval_key_id); 67 //lets delete the old values 68 $q = new DBQuery; 69 if ($this->sysval_key_id && $this->sysval_title) { 70 $q->setDelete('sysvals'); 71 $q->addWhere('sysval_key_id = ' . (int)$this->sysval_key_id); 72 $q->addWhere('sysval_title = \'' . $this->sysval_title . '\''); 73 if (!$q->exec()) { 74 $q->clear(); 75 return get_class($this) . '::store failed: ' . db_error(); 76 } 77 } 78 foreach ($values as $key => $value) { 79 $q->addTable('sysvals'); 80 $q->addInsert('sysval_key_id', $this->sysval_key_id); 81 $q->addInsert('sysval_title', $this->sysval_title); 82 $q->addInsert('sysval_value_id', $key); 83 $q->addInsert('sysval_value', $value); 84 if (!$q->exec()) { 85 $q->clear(); 86 return get_class($this) . '::store failed: ' . db_error(); 87 } 88 $q->clear(); 89 } 90 return null; 91 } 92 93 function delete() { 94 $q = new DBQuery; 95 if ($this->sysval_title) { 96 $q->setDelete('sysvals'); 97 $q->addWhere('sysval_title = \'' . $this->sysval_title . '\''); 98 if (!$q->exec()) { 99 $q->clear(); 100 return get_class($this) . '::delete failed <br />' . db_error(); 101 } 102 } 103 return null; 104 } 105 106 } 107 108 function parseFormatSysval($text, $syskey) { 109 $q = new DBQuery; 110 $q->addTable('syskeys'); 111 $q->addQuery('syskey_type, syskey_sep1, syskey_sep2'); 112 $q->addWhere('syskey_id = ' . (int)$syskey); 113 $q->exec(); 114 $row = $q->fetchRow(); 115 $q->clear(); 116 // type 0 = list 117 $sep1 = $row['syskey_sep1']; // item separator 118 $sep2 = $row['syskey_sep2']; // alias separator 119 120 // A bit of magic to handle newlines and returns as separators 121 // Missing sep1 is treated as a newline. 122 if (!isset($sep1) || empty($sep1)) { 123 $sep1 = "\n"; 124 } 125 if ($sep1 == "\\n") { 126 $sep1 = "\n"; 127 } 128 if ($sep1 == "\\r") { 129 $sep1 = "\r"; 130 } 131 132 $temp = explode($sep1, $text); 133 $arr = array(); 134 // We use trim() to make sure a numeric that has spaces 135 // is properly treated as a numeric 136 foreach ($temp as $item) { 137 if ($item) { 138 $sep2 = empty($sep2) ? "\n" : $sep2; 139 $temp2 = explode($sep2, $item); 140 if (isset($temp2[1])) { 141 $arr[trim($temp2[0])] = trim($temp2[1]); 142 } else { 143 $arr[trim($temp2[0])] = trim($temp2[0]); 144 } 145 } 146 } 147 return $arr; 148 } 149 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu Jan 8 03:00:03 2009 | Cross-referenced by PHPXref 0.7 |