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