1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15:
16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
17:
18: 19: 20: 21: 22: 23: 24:
25: class PimPluginCollection extends ItemCollection {
26:
27: 28: 29: 30: 31:
32: public function __construct() {
33: global $cfg;
34: parent::__construct($cfg['tab']['plugins'], 'idplugin');
35: $this->_setItemClass('PimPlugin');
36: }
37:
38: 39: 40: 41: 42:
43: public function create($name, $description, $author, $copyright, $mail, $website, $version, $foldername, $uuId, $active, $execOrder = 0) {
44: global $client;
45:
46: $nextId = $this->_getNextId();
47:
48:
49: $item = $this->createNewItem($nextId);
50: $item->set('idclient', $client);
51: $item->set('name', $name);
52: $item->set('description', $description);
53: $item->set('author', $author);
54: $item->set('copyright', $copyright);
55: $item->set('mail', $mail);
56: $item->set('website', $website);
57: $item->set('version', $version);
58: $item->set('folder', $foldername);
59: $item->set('uuid', $uuId);
60: $item->set('installed', date("Y-m-d H:i:s"), false);
61: $item->set('active', $active);
62:
63:
64: if ($execOrder == 0) {
65: $this->select();
66: $execOrder = $this->count();
67: }
68: $item->set("executionorder", $execOrder);
69:
70: $item->store();
71:
72: return $item;
73: }
74:
75: 76: 77: 78: 79:
80: protected function _getNextId() {
81: global $cfg;
82:
83: $sql = 'SELECT MAX(idplugin) AS id FROM ' . $cfg['tab']['plugins'];
84: $this->db->query($sql);
85:
86: if ($this->db->nextRecord()) {
87:
88: $result = $this->db->f('id');
89:
90:
91: if ($result < 10000) {
92: $result = 10000;
93: }
94:
95:
96: $result = $result + 10;
97:
98:
99: $result = substr($result, 0, strlen($result) - 1);
100:
101:
102: return cSecurity::toInteger($result . 0);
103: }
104: }
105:
106: }
107:
108: 109: 110:
111: class PimPlugin extends Item {
112:
113: 114: 115:
116: protected $_error;
117:
118: 119: 120: 121: 122:
123: public function __construct($id = false) {
124: global $cfg;
125: parent::__construct($cfg['tab']['plugins'], 'idplugin');
126: $this->_error = '';
127: if ($id !== false) {
128: $this->loadByPrimaryKey($id);
129: }
130: }
131:
132: 133: 134: 135: 136: 137: 138:
139: public function setField($name, $value, $bSafe = true) {
140: switch ($name) {
141: case 'idclient':
142: $value = (int) $value;
143: break;
144: case 'active':
145: $value = (int) $value;
146: break;
147: }
148:
149: return parent::setField($name, $value, $bSafe);
150: }
151:
152: 153: 154: 155: 156:
157: public function updateExecOrder($newOrder) {
158: $oldOrder = $this->get('executionorder');
159: $idplugin = $this->get("idplugin");
160:
161: $this->set('executionorder', $newOrder);
162: $this->store();
163:
164:
165: $pluginColl = new PimPluginCollection();
166: $pluginColl->select('executionorder >= "' . min($newOrder, $oldOrder) . '" AND executionorder <= "' . max($newOrder, $oldOrder) . '" AND idplugin != "' . $idplugin . '"', NULL, 'executionorder');
167:
168: while ($plugin = $pluginColl->next()) {
169: if ($newOrder < $oldOrder) {
170: $plugin->set("executionorder", $plugin->get("executionorder") + 1);
171: $plugin->store();
172: } else if ($oldOrder < $newOrder) {
173: $plugin->set("executionorder", $plugin->get("executionorder") - 1);
174: $plugin->store();
175: }
176: }
177: }
178: }
179: