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::toInteger($idartlang);
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 = $this->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: $starttime = $this->get("starttime");
149:
150: $db = cRegistry::getDb();
151: $sql = "SELECT author, title, idart FROM " . $cfg["tab"]["art_lang"] . " WHERE idartlang = " . (int) $idartlang;
152:
153: $db->query($sql);
154:
155: if ($db->nextRecord()) {
156: $idart = $db->f("idart");
157: $title = $db->f("title");
158: $author = $db->f("author");
159: }
160:
161:
162: $sql = "SELECT idcat FROM " . $cfg["tab"]["cat_art"] . " WHERE idart = " . (int) $idart;
163: $db->query($sql);
164:
165: if ($db->nextRecord()) {
166: $idcat = $db->f("idcat");
167: }
168:
169: $sql = "SELECT name FROM " . $cfg["tab"]["cat_lang"] . " WHERE idcat = " . (int) $idcat;
170: $db->query($sql);
171:
172: if ($db->nextRecord()) {
173: $catname = $db->f("name");
174: }
175:
176:
177: $starttime = strtotime($starttime);
178:
179: switch ($timeunit) {
180: case "Seconds":
181: $maxtime = $starttime + $timelimit;
182: break;
183: case "Minutes":
184: $maxtime = $starttime + ($timelimit * 60);
185: break;
186: case "Hours":
187: $maxtime = $starttime + ($timelimit * 3600);
188: break;
189: case "Days":
190: $maxtime = $starttime + ($timelimit * 86400);
191: break;
192: case "Weeks":
193: $maxtime = $starttime + ($timelimit * 604800);
194: break;
195: case "Months":
196: $maxtime = $starttime + ($timelimit * 2678400);
197: break;
198: case "Years":
199: $maxtime = $starttime + ($timelimit * 31536000);
200: break;
201: default:
202: $maxtime = $starttime + $timelimit;
203: }
204:
205: if ($email == 1) {
206: $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";
207:
208: $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));
209: $user = new cApiUser();
210:
211: if (isGroup($usersequence->get("iduser"))) {
212: $sql = "SELECT idgroupuser, user_id FROM " . $cfg["tab"]["groupmembers"] . " WHERE
213: group_id = '" . $db->escape($usersequence->get("iduser")) . "'";
214: $db->query($sql);
215:
216: while ($db->nextRecord()) {
217: $user->loadByPrimaryKey($db->f("user_id"));
218: $mailer->sendMail(NULL, $user->getField("email"), stripslashes(i18n('Workflow notification')), $filledMail);
219: }
220: } else {
221: $user->loadByPrimaryKey($usersequence->get("iduser"));
222: $mailer->sendMail(NULL, $user->getField("email"), stripslashes(i18n('Workflow notification')), $filledMail);
223: }
224: } else {
225: $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";
226:
227: $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));
228:
229: $user = new cApiUser();
230:
231: if (isGroup($usersequence->get("iduser"))) {
232:
233: $sql = "SELECT idgroupuser, user_id FROM " . $cfg["tab"]["groupmembers"] . " WHERE
234: group_id = '" . $db->escape($usersequence->get("iduser")) . "'";
235: $db->query($sql);
236:
237: while ($db->nextRecord()) {
238: $user->loadByPrimaryKey($db->f("user_id"));
239: $mailer->sendMail(NULL, $user->getField("email"), stripslashes(i18n('Workflow escalation')), $filledMail);
240: }
241: } else {
242: $user->loadByPrimaryKey($usersequence->get("iduser"));
243: $mailer->sendMail(NULL, $user->getField("email"), stripslashes(i18n('Workflow escalation')), $filledMail);
244: }
245: }
246: }
247: }
248:
249: if (parent::store()) {
250: $this->db->query("UPDATE " . $this->table . " SET `starttime`=NOW() WHERE `" . $this->getPrimaryKeyName() . "`='" . $this->get($this->getPrimaryKeyName()) . "'");
251: return true;
252: } else {
253: return false;
254: }
255: }
256:
257: }
258: