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: class WorkflowArtAllocations extends ItemCollection {
25:
26: 27: 28: 29: 30:
31: public function __construct() {
32: global $cfg;
33: parent::__construct($cfg["tab"]["workflow_art_allocation"], "idartallocation");
34: $this->_setItemClass("WorkflowArtAllocation");
35: }
36:
37: public function create($idartlang) {
38: global $cfg;
39:
40: $sql = "SELECT idartlang FROM " . $cfg["tab"]["art_lang"] . " WHERE idartlang = '" . cSecurity::escapeDB($idartlang, $this->db) . "'";
41:
42: $this->db->query($sql);
43: if (!$this->db->nextRecord()) {
44: $this->lasterror = i18n("Article doesn't exist", "workflow");
45: return false;
46: }
47:
48: $this->select("idartlang = '$idartlang'");
49:
50: if ($this->next() !== false) {
51: $this->lasterror = i18n("Article is already assigned to a usersequence step.", "workflow");
52: return false;
53: }
54:
55: $newitem = parent::createNewItem();
56: $newitem->setField("idartlang", $idartlang);
57: $newitem->store();
58:
59: return ($newitem);
60: }
61:
62: }
63:
64: 65: 66: 67: 68: 69: 70: 71: 72: 73:
74: class WorkflowArtAllocation extends Item {
75:
76: 77: 78: 79: 80:
81: public function __construct() {
82: global $cfg;
83:
84: parent::__construct($cfg["tab"]["workflow_art_allocation"], "idartallocation");
85: }
86:
87: public function getWorkflowItem() {
88: $userSequence = new WorkflowUserSequence();
89: $userSequence->loadByPrimaryKey($this->values["idusersequence"]);
90:
91: return ($userSequence->getWorkflowItem());
92: }
93:
94: 95: 96: 97: 98: 99: 100: 101:
102: public function currentItemPosition() {
103: $idworkflowitem = $this->get("idworkflowitem");
104:
105: $workflowItems = new WorkflowItems();
106: $workflowItems->select("idworkflowitem = '$idworkflowitem'");
107:
108: if (($item = $workflowItems->next()) !== false) {
109: return ($item->get("position"));
110: }
111: }
112:
113: 114: 115: 116: 117: 118: 119: 120:
121: public function currentUserPosition() {
122: return ($this->get("position"));
123: }
124:
125: 126: 127: 128: 129:
130: public function store() {
131: global $cfg;
132:
133: $mailer = new cMailer();
134:
135: if (array_key_exists("idusersequence", $this->modifiedValues)) {
136: $usersequence = new WorkflowUserSequence();
137: $usersequence->loadByPrimaryKey($this->values["idusersequence"]);
138:
139: $email = $usersequence->get("emailnoti");
140: $escal = $usersequence->get("escalationnoti");
141:
142: if ($email == 1 || $escal == 1) {
143:
144: $curEditor = getGroupOrUserName($usersequence->get("iduser"));
145: $idartlang = $this->get("idartlang");
146: $timeunit = $usersequence->get("timeunit");
147: $timelimit = $usersequence->get("timelimit");
148:
149: $db = cRegistry::getDb();
150: $sql = "SELECT author, title, idart FROM " . $cfg["tab"]["art_lang"] . " WHERE idartlang = '" . cSecurity::escapeDB($idartlang, $db) . "'";
151:
152: $db->query($sql);
153:
154: if ($db->nextRecord()) {
155: $idart = $db->f("idart");
156: $title = $db->f("title");
157: $author = $db->f("author");
158: }
159:
160:
161: $sql = "SELECT idcat FROM " . $cfg["tab"]["cat_art"] . " WHERE idart = '" . cSecurity::escapeDB($idart, $db) . "'";
162: $db->query($sql);
163:
164: if ($db->nextRecord()) {
165: $idcat = $db->f("idcat");
166: }
167:
168: $sql = "SELECT name FROM " . $cfg["tab"]["cat_lang"] . " WHERE idcat = '" . cSecurity::escapeDB($idcat, $db) . "'";
169: $db->query($sql);
170:
171: if ($db->nextRecord()) {
172: $catname = $db->f("name");
173: }
174:
175: $starttime = $this->get("starttime");
176:
177:
178: $starttime = strtotime(substr_replace(substr(substr($starttime, 0, 2) . chunk_split(substr($starttime, 2, 6), 2, "-") . chunk_split(substr($starttime, 8), 2, ":"), 0, 19), " ", 10, 1));
179:
180: switch ($timeunit) {
181: case "Seconds":
182: $maxtime = $starttime + $timelimit;
183: break;
184: case "Minutes":
185: $maxtime = $starttime + ($timelimit * 60);
186: break;
187: case "Hours":
188: $maxtime = $starttime + ($timelimit * 3600);
189: break;
190: case "Days":
191: $maxtime = $starttime + ($timelimit * 86400);
192: break;
193: case "Weeks":
194: $maxtime = $starttime + ($timelimit * 604800);
195: break;
196: case "Months":
197: $maxtime = $starttime + ($timelimit * 2678400);
198: break;
199: case "Years":
200: $maxtime = $starttime + ($timelimit * 31536000);
201: break;
202: default:
203: $maxtime = $starttime + $timelimit;
204: }
205:
206: if ($email == 1) {
207: $email = "Hello %s,\n\n" . "you are assigned as the next editor for the Article %s.\n\n" . "More informations:\n" . "Article: %s\n" . "Category: %s\n" . "Editor: %s\n" . "Author: %s\n" . "Editable from: %s\n" . "Editable to: %s\n";
208:
209: $filledMail = sprintf($email, $curEditor, $title, $title, $catname, $curEditor, $author, date("Y-m-d H:i:s", $starttime), date("Y-m-d H:i:s", $maxtime));
210: $user = new cApiUser();
211:
212: if (isGroup($usersequence->get("iduser"))) {
213: $sql = "select idgroupuser, user_id FROM " . $cfg["tab"]["groupmembers"] . " WHERE
214: group_id = '" . cSecurity::escapeDB($usersequence->get("iduser"), $db) . "'";
215: $db->query($sql);
216:
217: while ($db->nextRecord()) {
218: $user->loadByPrimaryKey($db->f("user_id"));
219: $mailer->sendMail(null, $user->getField("email"), stripslashes(i18n('Workflow notification')), $filledMail);
220: }
221: } else {
222: $user->loadByPrimaryKey($usersequence->get("iduser"));
223: $mailer->sendMail(null, $user->getField("email"), stripslashes(i18n('Workflow notification')), $filledMail);
224: }
225: } else {
226: $email = "Hello %s,\n\n" . "you are assigned as the escalator for the Article %s.\n\n" . "More informations:\n" . "Article: %s\n" . "Category: %s\n" . "Editor: %s\n" . "Author: %s\n" . "Editable from: %s\n" . "Editable to: %s\n";
227:
228: $filledMail = sprintf($email, $curEditor, $title, $title, $catname, $curEditor, $author, date("Y-m-d H:i:s", $starttime), date("Y-m-d H:i:s", $maxtime));
229:
230: $user = new cApiUser();
231:
232: if (isGroup($usersequence->get("iduser"))) {
233:
234: $sql = "select idgroupuser, user_id FROM " . $cfg["tab"]["groupmembers"] . " WHERE
235: group_id = '" . cSecurity::escapeDB($usersequence->get("iduser"), $db) . "'";
236: $db->query($sql);
237:
238: while ($db->nextRecord()) {
239: $user->loadByPrimaryKey($db->f("user_id"));
240: $mailer->sendMail(null, $user->getField("email"), stripslashes(i18n('Workflow escalation')), $filledMail);
241: }
242: } else {
243: $user->loadByPrimaryKey($usersequence->get("iduser"));
244: $mailer->sendMail(null, $user->getField("email"), stripslashes(i18n('Workflow escalation')), $filledMail);
245: }
246: }
247: }
248: }
249:
250: if (parent::store()) {
251: $this->db->query("UPDATE " . $this->table . " SET `starttime`=NOW() WHERE `" . $this->primaryKey . "`='" . $this->get($this->primaryKey) . "'");
252: return true;
253: } else {
254: return false;
255: }
256: }
257:
258: }
259: