Overview

Packages

  • CONTENIDO
  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • mpAutoloaderClassMap
  • None
  • PHP
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SIWECOS
    • SmartyWrapper
    • UrlShortener
    • UserForum
    • Workflow
  • PluginManager
  • Setup
    • Form
    • GUI
    • Helper
      • Environment
      • Filesystem
      • MySQL
      • PHP
    • UpgradeJob

Classes

  • Workflow
  • WorkflowAction
  • WorkflowActions
  • WorkflowAllocation
  • WorkflowAllocations
  • WorkflowArtAllocation
  • WorkflowArtAllocations
  • WorkflowItem
  • WorkflowItems
  • Workflows
  • WorkflowTask
  • WorkflowTasks
  • WorkflowUserSequence
  • WorkflowUserSequences

Functions

  • createNewWorkflow
  • doWorkflowAction
  • editWorkflowStep
  • getActionSelect
  • getCatLang
  • getCurrentUserSequence
  • getLastWorkflowStatus
  • getTimeUnitSelector
  • getUsers
  • getWorkflowForCat
  • getWorkflowForUserSequence
  • getWorkflowList
  • getWorkflowUsers
  • isCurrentEditor
  • piworkflowAllowArticleEdit
  • piworkflowCategoryColumns
  • piworkflowCategoryRenderColumn
  • piworkflowCreateTasksFolder
  • piworkflowProcessActions
  • piworkflowProcessArticleColumns
  • piworkflowRenderAction
  • piworkflowRenderColumn
  • prepareWorkflowItems
  • setUserSequence
  • workflowInherit
  • workflowSelect
  • Overview
  • Package
  • Function
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: /**
  3:  * This file contains the workflow functions.
  4:  *
  5:  * @package Plugin
  6:  * @subpackage Workflow
  7:  * @author Timo Hummel
  8:  * @copyright four for business AG <www.4fb.de>
  9:  * @license http://www.contenido.org/license/LIZENZ.txt
 10:  * @link http://www.4fb.de
 11:  * @link http://www.contenido.org
 12:  */
 13: 
 14: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
 15: 
 16: cInclude("includes", "functions.con.php");
 17: 
 18: plugin_include('workflow', 'classes/class.workflowitems.php');
 19: 
 20: /**
 21:  * @param $listid
 22:  * @param $default
 23:  *
 24:  * @return string
 25:  * @throws cDbException
 26:  * @throws cException
 27:  * @throws cInvalidArgumentException
 28:  */
 29: function getUsers($listid, $default) {
 30:     global $idclient, $cfg, $auth;
 31: 
 32:     $userColl = new cApiUserCollection();
 33:     $users = $userColl->getAccessibleUsers(explode(',', $auth->auth['perm']));
 34:     $groupColl = new cApiGroupCollection();
 35:     $groups = $groupColl->getAccessibleGroups(explode(',', $auth->auth['perm']));
 36: 
 37:     $tpl2 = new cTemplate();
 38:     $tpl2->set('s', 'NAME', 'user' . $listid);
 39:     $tpl2->set('s', 'CLASS', 'text_small');
 40:     $tpl2->set('s', 'OPTIONS', 'size=1');
 41: 
 42:     $tpl2->set('d', 'VALUE', 0);
 43:     $tpl2->set('d', 'CAPTION', '--- ' . i18n("None", "workflow") . ' ---');
 44:     if ($default == 0) {
 45:         $tpl2->set('d', 'SELECTED', 'SELECTED');
 46:     } else {
 47:         $tpl2->set('d', 'SELECTED', '');
 48:     }
 49:     $tpl2->next();
 50: 
 51:     if (is_array($users)) {
 52:         foreach ($users as $key => $value) {
 53:             $tpl2->set('d', 'VALUE', $key);
 54:             $tpl2->set('d', 'CAPTION', $value["realname"] . " (" . $value["username"] . ")");
 55: 
 56:             if ($default == $key) {
 57:                 $tpl2->set('d', 'SELECTED', 'SELECTED');
 58:             } else {
 59:                 $tpl2->set('d', 'SELECTED', '');
 60:             }
 61: 
 62:             $tpl2->next();
 63:         }
 64:     }
 65: 
 66:     $tpl2->set('d', 'VALUE', '0');
 67:     $tpl2->set('d', 'CAPTION', '------------------------------------');
 68:     $tpl2->set('d', 'SELECTED', 'disabled');
 69:     $tpl2->next();
 70: 
 71:     if (is_array($groups)) {
 72:         foreach ($groups as $key => $value) {
 73:             $tpl2->set('d', 'VALUE', $key);
 74:             $tpl2->set('d', 'CAPTION', $value["groupname"]);
 75: 
 76:             if ($default == $key) {
 77:                 $tpl2->set('d', 'SELECTED', 'SELECTED');
 78:             } else {
 79:                 $tpl2->set('d', 'SELECTED', '');
 80:             }
 81: 
 82:             $tpl2->next();
 83:         }
 84:     }
 85: 
 86:     return $tpl2->generate($cfg['path']['templates'] . $cfg['templates']['generic_select'], true);
 87: }
 88: 
 89: /**
 90:  * @param $uid
 91:  *
 92:  * @return bool
 93:  * @throws cDbException
 94:  * @throws cException
 95:  */
 96: function isCurrentEditor($uid) {
 97:     global $auth, $cfg;
 98: 
 99:     // Check if the UID is a group. If yes, check if we are in it
100:     $user = new cApiUser();
101:     if ($user->loadByPrimaryKey($uid) == false) {
102:         $db2 = cRegistry::getDb();
103: 
104:         // Yes, it's a group. Let's try to load the group members!
105:         $sql = "SELECT user_id FROM " . $cfg["tab"]["groupmembers"] . "
106:                 WHERE group_id = '" . $db2->escape($uid) . "'";
107: 
108:         $db2->query($sql);
109: 
110:         while ($db2->nextRecord()) {
111:             if ($db2->f("user_id") == $auth->auth["uid"]) {
112:                 return true;
113:             }
114:         }
115:     } else {
116:         if ($uid == $auth->auth["uid"]) {
117:             return true;
118:         }
119:     }
120: 
121:     return false;
122: }
123: 
124: /**
125:  * @param $idartlang
126:  * @param $idusersequence
127:  *
128:  * @return bool|string
129:  * @throws cDbException
130:  * @throws cException
131:  * @throws cInvalidArgumentException
132:  */
133: function getActionSelect($idartlang, $idusersequence) {
134:     global $cfg;
135: 
136:     $workflowActions = new WorkflowActions();
137:     $allActions      = $workflowActions->getAvailableWorkflowActions();
138: 
139:     $wfSelect = new cTemplate();
140:     $wfSelect->set('s', 'NAME', 'wfselect' . $idartlang);
141:     $wfSelect->set('s', 'CLASS', 'text_medium');
142: 
143:     $userSequence = new WorkflowUserSequence();
144:     $userSequence->loadByPrimaryKey($idusersequence);
145: 
146:     $workflowItem = $userSequence->getWorkflowItem();
147: 
148:     if ($workflowItem === false) {
149:         return;
150:     }
151: 
152:     $wfRights = $workflowItem->getStepRights();
153: 
154:     $artAllocation = new WorkflowArtAllocations();
155:     $artAllocation->select("idartlang = '$idartlang'");
156: 
157:     if (($obj = $artAllocation->next()) !== false) {
158:         $laststep = $obj->get("lastusersequence");
159:     }
160: 
161:     $bExistOption = false;
162:     if ($laststep != $idusersequence) {
163:         $wfSelect->set('d', 'VALUE', 'next');
164:         $wfSelect->set('d', 'CAPTION', i18n("Confirm", "workflow"));
165:         $wfSelect->set('d', 'SELECTED', 'SELECTED');
166:         $wfSelect->next();
167:         $bExistOption = true;
168:     }
169: 
170:     if ($wfRights["last"] == true) {
171:         $wfSelect->set('d', 'VALUE', 'last');
172:         $wfSelect->set('d', 'CAPTION', i18n("Back to last editor", "workflow"));
173:         $wfSelect->set('d', 'SELECTED', '');
174:         $wfSelect->next();
175:         $bExistOption = true;
176:     }
177: 
178:     if ($wfRights["reject"] == true) {
179:         $wfSelect->set('d', 'VALUE', 'reject');
180:         $wfSelect->set('d', 'CAPTION', i18n("Reject article", "workflow"));
181:         $wfSelect->set('d', 'SELECTED', '');
182:         $wfSelect->next();
183:         $bExistOption = true;
184:     }
185: 
186:     if ($wfRights["revise"] == true) {
187:         $wfSelect->set('d', 'VALUE', 'revise');
188:         $wfSelect->set('d', 'CAPTION', i18n("Revise article", "workflow"));
189:         $wfSelect->set('d', 'SELECTED', '');
190:         $wfSelect->next();
191:         $bExistOption = true;
192:     }
193: 
194:     if ($bExistOption)
195:         return $wfSelect->generate($cfg['path']['templates'] . $cfg['templates']['generic_select'], true);
196:     else {
197:         return false;
198:     }
199: }
200: 
201: /**
202:  * function for inserting todos in wokflow_art_allocation used, when a workflow
203:  * is associated with a category in content->category
204:  *
205:  * @param $idartlang
206:  * @param $defaultidworkflow
207:  *
208:  * @return bool
209:  * @throws cDbException
210:  * @throws cException
211:  * @throws cInvalidArgumentException
212:  */
213: function setUserSequence($idartlang, $defaultidworkflow) {
214:     $wfaa = new WorkflowArtAllocations();
215:     $wfaa->select("idartlang = '$idartlang'");
216:     $idusersequence = 0;
217: 
218:     if (($associatedUserSequence = $wfaa->next()) !== false) {
219:         $idartallocation = $associatedUserSequence->get("idartallocation");
220:         $wfaa->delete($idartallocation);
221:     }
222: 
223:     if ($defaultidworkflow != -1) {
224:         $newObj = $wfaa->create($idartlang);
225: 
226:         if (!$newObj) {
227:             return false;
228:         }
229: 
230:         // Get the first idusersequence for the new item
231:         $workflowItems = new WorkflowItems();
232:         $workflowItems->select("idworkflow = '$defaultidworkflow' AND position = '1'");
233: 
234:         if (($obj = $workflowItems->next()) !== false) {
235:             $firstitem = $obj->get("idworkflowitem");
236:         }
237: 
238:         $workflowUserSequences = new WorkflowUserSequences();
239:         $workflowUserSequences->select("idworkflowitem = '$firstitem' AND position = '1'");
240: 
241:         if (($obj = $workflowUserSequences->next()) !== false) {
242:             $firstIDUserSequence = $obj->get("idusersequence");
243:         }
244: 
245:         $newObj->set("idusersequence", $firstIDUserSequence);
246:         $newObj->store();
247: 
248:         $idusersequence = $newObj->get("idusersequence");
249:         $associatedUserSequence = $newObj;
250:     }
251: }
252: 
253: /**
254:  * Returns current user sequence, either from workflow article allocations or
255:  * from workflow user sequnces.
256:  *
257:  * @param int $idartlang         Article language id
258:  * @param int $defaultidworkflow Default workflow id
259:  *
260:  * @return int false of found user sequence or false
261:  * @throws cDbException
262:  * @throws cException
263:  */
264: function getCurrentUserSequence($idartlang, $defaultidworkflow) {
265:     $wfaa = new WorkflowArtAllocations();
266:     $wfaa->select("idartlang = '$idartlang'");
267:     $idusersequence = 0;
268: 
269:     if (($associatedUserSequence = $wfaa->next()) !== false) {
270:         $idusersequence = $associatedUserSequence->get("idusersequence");
271:     }
272: 
273:     if ($idusersequence == 0) {
274:         if ($associatedUserSequence != false) {
275:             $newObj = $associatedUserSequence;
276:         } else {
277:             $newObj = $wfaa->create($idartlang);
278: 
279:             if (!$newObj) {
280:                 return false;
281:             }
282:         }
283: 
284:         // Get the first idusersequence for the new item
285:         $workflowItems = new WorkflowItems();
286:         $workflowItems->select("idworkflow = '$defaultidworkflow' AND position = '1'");
287: 
288:         if (($obj = $workflowItems->next()) !== false) {
289:             $firstitem = $obj->get("idworkflowitem");
290:         }
291: 
292:         $workflowUserSequences = new WorkflowUserSequences();
293:         $workflowUserSequences->select("idworkflowitem = '$firstitem' AND position = '1'");
294: 
295:         if (($obj = $workflowUserSequences->next()) !== false) {
296:             $firstIDUserSequence = $obj->get("idusersequence");
297:         }
298: 
299:         $newObj->set("idusersequence", $firstIDUserSequence);
300:         $newObj->store();
301: 
302:         $idusersequence = $newObj->get("idusersequence");
303:         $associatedUserSequence = $newObj;
304:     }
305: 
306:     return $idusersequence;
307: }
308: 
309: /**
310:  * @param $idartlang
311:  *
312:  * @return bool|string
313:  * @throws cDbException
314:  * @throws cException
315:  */
316: function getLastWorkflowStatus($idartlang) {
317:     $wfaa = new WorkflowArtAllocations();
318: 
319:     $wfaa->select("idartlang = '$idartlang'");
320: 
321:     if (($associatedUserSequence = $wfaa->next()) !== false) {
322:         $laststatus = $associatedUserSequence->get("laststatus");
323:     } else {
324:         return false;
325:     }
326: 
327:     switch ($laststatus) {
328:         case "reject":
329:             return (i18n("Rejected", "workflow"));
330:             break;
331:         case "revise":
332:             return (i18n("Revised", "workflow"));
333:             break;
334:         case "last":
335:             return (i18n("Last", "workflow"));
336:             break;
337:         case "confirm":
338:             return (i18n("Confirmed", "workflow"));
339:             break;
340:         default:
341:             return (i18n("None", "workflow"));
342:             break;
343:     }
344: }
345: 
346: /**
347:  * @param $idartlang
348:  * @param $action
349:  *
350:  * @throws cDbException
351:  * @throws cException
352:  */
353: function doWorkflowAction($idartlang, $action) {
354:     global $cfg, $idcat;
355: 
356:     $idartlang = cSecurity::toInteger($idartlang);
357: 
358:     switch ($action) {
359:         case "last":
360:             $artAllocations = new WorkflowArtAllocations();
361:             $artAllocations->select("idartlang = {$idartlang}");
362: 
363:             if (($obj = $artAllocations->next()) !== false) {
364:                 $usersequence = new WorkflowUserSequence();
365:                 $usersequence->loadByPrimaryKey($obj->get("idusersequence"));
366: 
367:                 $workflowitem = $usersequence->getWorkflowItem();
368: 
369:                 $idworkflow = $workflowitem->get("idworkflow");
370:                 $newpos = $workflowitem->get("position") - 1;
371: 
372:                 if ($newpos < 1) {
373:                     $newpos = 1;
374:                 }
375: 
376:                 $workflowitems = new WorkflowItems();
377:                 $workflowitems->select("idworkflow = '$idworkflow' AND position = " . (int) $newpos);
378: 
379:                 if (($nextObj = $workflowitems->next()) !== false) {
380:                     $userSequences = new WorkflowUserSequences();
381:                     $idworkflowitem = $nextObj->get("idworkflowitem");
382:                     $userSequences->select("idworkflowitem = '$idworkflowitem'");
383: 
384:                     if (($nextSeqObj = $userSequences->next()) !== false) {
385:                         $obj->set("lastusersequence", $obj->get("idusersequence"));
386:                         $obj->set("idusersequence", $nextSeqObj->get("idusersequence"));
387:                         $obj->set("laststatus", "last");
388:                         $obj->store();
389:                     }
390:                 }
391:             }
392:             break;
393:         case "next":
394:             $artAllocations = new WorkflowArtAllocations();
395:             $artAllocations->select("idartlang = {$idartlang}");
396: 
397:             if (($obj = $artAllocations->next()) !== false) {
398:                 $usersequence = new WorkflowUserSequence();
399:                 $usersequence->loadByPrimaryKey($obj->get("idusersequence"));
400: 
401:                 $workflowitem = $usersequence->getWorkflowItem();
402: 
403:                 $idworkflow = $workflowitem->get("idworkflow");
404:                 $newpos = $workflowitem->get("position") + 1;
405: 
406:                 $workflowitems = new WorkflowItems();
407:                 $workflowitems->select("idworkflow = '$idworkflow' AND position = " . (int) $newpos);
408: 
409:                 if (($nextObj = $workflowitems->next()) !== false) {
410:                     $userSequences = new WorkflowUserSequences();
411:                     $idworkflowitem = $nextObj->get("idworkflowitem");
412:                     $userSequences->select("idworkflowitem = '$idworkflowitem'");
413: 
414:                     if (($nextSeqObj = $userSequences->next()) !== false) {
415:                         $obj->set("lastusersequence", '10');
416:                         $obj->set("idusersequence", $nextSeqObj->get("idusersequence"));
417:                         $obj->set("laststatus", "confirm");
418:                         $obj->store();
419:                     }
420:                 } else {
421:                     $workflowitems->select("idworkflow = '$idworkflow' AND position = " . (int) $workflowitem->get("position"));
422:                     if (($nextObj = $workflowitems->next()) !== false) {
423:                         $userSequences = new WorkflowUserSequences();
424:                         $idworkflowitem = $nextObj->get("idworkflowitem");
425:                         $userSequences->select("idworkflowitem = '$idworkflowitem'");
426: 
427:                         if (($nextSeqObj = $userSequences->next()) !== false) {
428:                             $obj->set("lastusersequence", $obj->get("idusersequence"));
429:                             $obj->set("idusersequence", $nextSeqObj->get("idusersequence"));
430:                             $obj->set("laststatus", "confirm");
431:                             $obj->store();
432:                         }
433:                     }
434:                 }
435:             }
436:             break;
437:         case "reject":
438:             $artAllocations = new WorkflowArtAllocations();
439:             $artAllocations->select("idartlang = {$idartlang}");
440: 
441:             if (($obj = $artAllocations->next()) !== false) {
442:                 $usersequence = new WorkflowUserSequence();
443:                 $usersequence->loadByPrimaryKey($obj->get("idusersequence"));
444: 
445:                 $workflowitem = $usersequence->getWorkflowItem();
446: 
447:                 $idworkflow = $workflowitem->get("idworkflow");
448:                 $newpos = 1;
449: 
450:                 $workflowitems = new WorkflowItems();
451:                 $workflowitems->select("idworkflow = '$idworkflow' AND position = " . (int) $newpos);
452: 
453:                 if (($nextObj = $workflowitems->next()) !== false) {
454:                     $userSequences = new WorkflowUserSequences();
455:                     $idworkflowitem = $nextObj->get("idworkflowitem");
456:                     $userSequences->select("idworkflowitem = '$idworkflowitem'");
457: 
458:                     if (($nextSeqObj = $userSequences->next()) !== false) {
459:                         $obj->set("lastusersequence", $obj->get("idusersequence"));
460:                         $obj->set("idusersequence", $nextSeqObj->get("idusersequence"));
461:                         $obj->set("laststatus", "reject");
462:                         $obj->store();
463:                     }
464:                 }
465:             }
466:             break;
467: 
468:         case "revise":
469:             $db = cRegistry::getDb();
470:             $sql = "SELECT idart, idlang FROM " . $cfg["tab"]["art_lang"] . " WHERE idartlang = " . $idartlang;
471:             $db->query($sql);
472:             $db->nextRecord();
473:             $idart = $db->f("idart");
474:             $idlang = $db->f("idlang");
475: 
476:             $newidart = conCopyArticle($idart, $idcat, "foo");
477: 
478:             break;
479:         default:
480:     }
481: }
482: 
483: /**
484:  * @param $usersequence
485:  *
486:  * @return bool|mixed
487:  * @throws cDbException
488:  * @throws cException
489:  */
490: function getWorkflowForUserSequence($usersequence) {
491:     $usersequences = new WorkflowUserSequences();
492:     $workflowitems = new WorkflowItems();
493:     $usersequences->select("idusersequence = '$usersequence'");
494: 
495:     if (($obj = $usersequences->next()) !== false) {
496:         $idworkflowitem = $obj->get("idworkflowitem");
497:     } else {
498:         return false;
499:     }
500: 
501:     $workflowitems->select("idworkflowitem = '$idworkflowitem'");
502:     if (($obj = $workflowitems->next()) !== false) {
503:         return $obj->get("idworkflow");
504:     } else {
505:         return false;
506:     }
507: }
508: 
509: /**
510:  * @param $listid
511:  * @param $default
512:  * @param $idcat
513:  *
514:  * @return string
515:  */
516: function workflowSelect($listid, $default, $idcat) {
517:     global $idclient, $cfg, $frame, $area, $workflowworkflows, $client, $lang, $wfcache, $workflowSelectBox;
518: 
519:     $oSelectBox = new cHTMLSelectElement('workflow');
520:     $oSelectBox = $workflowSelectBox;
521: 
522:     $default = (int) $default;
523:     $workflowSelectBox->updateAttributes(array(
524:         "id" => "wfselect" . $idcat
525:     ));
526:     $workflowSelectBox->updateAttributes(array(
527:         "name" => "wfselect" . $idcat
528:     ));
529:     $workflowSelectBox->setDefault($default);
530: 
531:     $sButton = '<a href="javascript:setWorkflow(' . $idcat . ', \'' . "wfselect" . $idcat . '\')"><img src="' . $cfg["path"]["images"] . 'submit.gif" alt="" class="spaced"></a>';
532: 
533:     return $workflowSelectBox->render() . $sButton;
534: }
535: 
536: /**
537:  * @param $idcat
538:  *
539:  * @return string
540:  */
541: function workflowInherit($idcat) {
542:     global $idclient, $cfg, $frame, $area, $workflowworkflows, $sess;
543:     $sUrl = $sess->url("main.php?area=$area&frame=$frame&modidcat=$idcat&action=workflow_inherit_down");
544:     $sButton = '<a href="' . $sUrl . '"><img src="' . $cfg["path"]["images"] . 'pfeil_runter.gif" class="spaced" title="' . i18n("Inherit workflow to sub-categories", "workflow") . '"></a>';
545:     return $sButton;
546: }
547: 
548: ?>
CMS CONTENIDO 4.10.1 API documentation generated by ApiGen 2.8.0