Caravel CMS PHP Cross Reference Content Management Systems

Source: /apps/Workflow/Workflow.php - 345 lines - 13848 bytes - Summary - Text - Print

   1  <?
   2  require_once(T_CODE_BASE . 'SQL/mnDB.php');
   3  require_once(T_WIDGET_BASE . 'FormBuilderOptionWidget.php');
   4  
   5  class Workflow extends App
   6    {
   7    
   8    function _connect()
   9        {
  10        if(is_readable(T_APP_BASE . "Workflow/.dbrc"))
  11            $dsn = mnDB::getLoginInfo(T_APP_BASE . "Workflow/.dbrc");
  12        else
  13            $dsn = mnDB::getLoginInfo('Workflow');
  14        $this->db = mnDB::connect($dsn, true);
  15  
  16        if(mnDB::isError($this->db))
  17            return new mnError("Workflow::_connect(): ". $this->db->getMessage(), __FILE__, __LINE__);
  18        }
  19    
  20    function getContent()
  21        {
  22        if($this->settingsVars['workflowID'] == "")
  23            return "No workflow ID has been set.";
  24          
  25        // connect to the workflow db
  26        Workflow::_connect();
  27        
  28        if(isset($this->httpVars['accept']))
  29            {
  30            // connect to the workflow db
  31            $query = "SELECT entity_id, data FROM workflow where workflow_id = '" . $this->settingsVars['workflowID'] . "' AND approver = '" . T_USER . "' AND entity_id = " . $this->httpVars['entity_id'];
  32            $res = $this->db->query($query);
  33            if(!mnDB::isError($res)) 
  34                {
  35                if($row = $res->fetchrow(DB_FETCHMODE_ASSOC))
  36                    {
  37                    $row   = array_change_key_case($row, CASE_LOWER);
  38                    $data  = unserialize($row['data']);
  39                    }
  40                }
  41          
  42            if($this->settingsVars['workflowComment'])
  43                {
  44                $commentsquery = str_replace("|comments|", $this->httpVars['wflowcomments'], $this->settingsVars['workflowCommentQuery']);
  45                
  46                foreach($data as $k => $v)
  47                    {
  48                    if($data[$k]['post_queries'] == "")
  49                        $data[$k]['post_queries'] = $commentsquery;
  50                    else
  51                        $data[$k]['post_queries'] .= "\n" . "#" . "\n" . $commentsquery;       
  52                    }
  53                }    
  54                      
  55            $data = FormBuilderOptionWidget::generateQueries($data);
  56            if($this->settingsVars['workflowMod'])
  57                {
  58                FormBuilderOptionWidget::executeStoreQueries($data, $this->httpVars, T_APP_BASE . "EmailFeedback/.dbrc");
  59                }
  60            else
  61                {
  62                foreach($data as $k => $v)
  63                    $values[$v['name']] = $v['value'];
  64                FormBuilderOptionWidget::executeStoreQueries($data, $values, T_APP_BASE . "EmailFeedback/.dbrc");
  65                }    
  66            
  67            $query = "DELETE FROM workflow WHERE entity_id = " . $this->httpVars['entity_id'];
  68            
  69            $res = $this->db->query($query);
  70            }    
  71        else if(isset($this->httpVars['reject']))    
  72            {
  73            // connect to the workflow db
  74            $query = "DELETE FROM workflow WHERE entity_id = " . $this->httpVars['entity_id'];
  75            
  76            $res = $this->db->query($query);          
  77            }
  78           
  79        $query = "SELECT entity_id, data FROM workflow where workflow_id = '" . $this->settingsVars['workflowID'] . "' AND approver = '" . T_USER . "'";
  80        $res = $this->db->query($query);
  81        if(!mnDB::isError($res))
  82          {
  83          while($row = $res->fetchrow(DB_FETCHMODE_ASSOC))
  84            {
  85            $row             = array_change_key_case($row, CASE_LOWER);
  86            $workflow_stuff[$row['entity_id']]  = unserialize($row['data']); 
  87            if(!isset($first_id))
  88                $first_id = $row['entity_id'];
  89            }
  90          }
  91          
  92        if(!is_array($workflow_stuff))
  93            $workflow_stuff = array();
  94            
  95        if(!is_array($workflow_stuff[$first_id]))
  96            $workflow_stuff[$first_id] = array();      
  97        
  98        
  99        if($this->settingsVars['workflowCompareQuery'] != "")
 100            {    
 101            $dsn = mnDB::getLoginInfo(T_APP_BASE . "EmailFeedback/.dbrc");
 102            $this->stodb = mnDB::connect($dsn, true);
 103  
 104            foreach($workflow_stuff[$first_id] as $k => $v)
 105                {
 106                $this->settingsVars['workflowCompareQuery'] = str_replace("|" . $v['name'] . "|", $v['value'],$this->settingsVars['workflowCompareQuery']);
 107                }
 108  
 109            $total = 0;
 110            $res = $this->stodb->query($this->settingsVars['workflowCompareQuery']);
 111            if(!mnDB::isError($res))
 112                {
 113                while($row = $res->fetchrow(DB_FETCHMODE_ASSOC))
 114                    {
 115                    $row             = array_change_key_case($row, CASE_LOWER);
 116  
 117                    if(isset($num))
 118                        {
 119                        if($this->settingsVars['workflowMod'])
 120                            $extra = "\n";
 121                        else
 122                            $extra = "<br />";    
 123                        $newtype = "textarea";
 124                        $total++;
 125                        }
 126                    else
 127                        {
 128                        $newtype = "text";    
 129                        $extra = "";
 130                        }
 131                    $num = 1;
 132                    foreach($row as $k => $v)
 133                        {
 134                        $newk = str_replace("_", " ", $k);
 135                        $newk = preg_replace("/(^(\w*?)|(\w{4,}?))/e", "ucfirst('$1')", $newk);
 136                        $compare[$num]['label'] = $newk;
 137                        $compare[$num]['value'] .= $extra . $v;
 138                        $compare[$num]['name']  = $k;
 139                        $compare[$num]['def']   = $v;
 140                        $compare[$num]['label_alignment']  = 'middle';
 141                        $compare[$num]['label_textalignment']   = 'center';
 142                        if($this->settingsVars['workflowMod'])
 143                            {
 144                            $compare[$num]['type']   = $newtype;
 145                            $compare[$num]['readonly']   = 'disabled';
 146                            
 147                            if($newtype == "text")
 148                                $compare[$num]['size']   = '60';
 149                            else
 150                                {
 151                                $compare[$num]['cols']   = '10';    
 152                                $compare[$num]['rows']   = $total;
 153                                }
 154                            }
 155                        else
 156                            {    
 157                            $compare[$num]['type']   = $newtype;
 158                            }
 159                        $num++;
 160                        }
 161                    }
 162                }
 163                
 164                
 165            if(!is_array($compare))
 166                $compare = array();              
 167                
 168                
 169            if($this->settingsVars['workflowCompareDisplay'] == 'interlace')
 170                {    
 171                foreach($compare as $k => $v)    
 172                    {
 173                    array_splice($workflow_stuff[$first_id], (($k*2) - 1) + $this->settingsVars['workflowInterlace'], 0, array($v));              
 174                    }
 175                }  
 176  
 177            foreach($workflow_stuff[$first_id] as $k => $v)
 178                {
 179                $this->settingsVars['workflowCompareQuery'] = str_replace("|" . $v['name'] . "|", $v['value'],$this->settingsVars['workflowCompareQuery']);
 180                }
 181            $res = $this->stodb->query($this->settingsVars['workflowCompareQuery']);
 182            if(!mnDB::isError($res))
 183                {
 184                while($row = $res->fetchrow(DB_FETCHMODE_ASSOC))
 185                    {
 186                    $row             = array_change_key_case($row, CASE_LOWER);
 187                    
 188                    $num = 1;
 189                    foreach($row as $k => $v)
 190                        {
 191                        $newk = str_replace("_", " ", $k);
 192                        //$newk = preg_replace("/(^(\w*?)|(\w{4,}?))/e", "ucfirst('$1')", $newk);
 193                        $newk = strtoupper(substr($newk,0,1))."".substr($newk,1);
 194                        $compare[$num]['label'] = $newk;
 195                        $compare[$num]['value'] = $v;
 196                        $compare[$num]['name']  = $k;
 197                        $compare[$num]['def']   = $v;
 198                        if($this->settingsVars['workflowMod'])
 199                            {
 200                            $compare[$num]['type']   = 'text';
 201                            $compare[$num]['readonly']   = 'disabled';
 202                            $compare[$num]['size']   = '30';
 203                            }
 204                        else
 205                            {    
 206                            $compare[$num]['type']   = 'text';
 207                            }
 208                        $num++;
 209                        }
 210                    }
 211                }
 212                
 213            if($this->settingsVars['workflowCompareDisplay'] == 'interlace')
 214                {    
 215                foreach($compare as $k => $v)    
 216                    {
 217                    array_splice($workflow_stuff[$first_id], (($k*2) - 1) + $this->settingsVars['workflowInterlace'], 0, array($v));              
 218                    }
 219                }     
 220            }
 221                    
 222        $f = FormWidget::init('', 'form.nonsettings.tpl.html');
 223        $f->name('worlflow');
 224        $f->html('<div id="cv_form" style="background-color: #FFFFFF; padding: 0px; margin: 0px; width: 100%;"><div style="background-color: #FFFFFF; margin-left: 10px;">');
 225        if($first_id != "")
 226            {
 227            $f->html("<div style='margin-top: 5px;'>There are " . count($workflow_stuff) . " items waiting for your approval.<br />&nbsp;</div>");
 228            $f->hidden('entity_id', $first_id);
 229  
 230            foreach($workflow_stuff[$first_id] as $k => $v)
 231                {
 232                $value[$v['name']] = $value[$v['value']];
 233                $workflow_stuff[$first_id][$k]['def'] = $v['value'];
 234                }
 235                  
 236            if($this->settingsVars['workflowCompareDisplay'] == 'column')
 237                {
 238                $f->html('<div style="float: left; width:40%;">');
 239                $f->section('p1');
 240                foreach($compare as $k => $v)
 241                    {
 242                    if ($v['type'] != 'html' && $v['type'] != 'newsection' && $v['type'] != 'linebreak' && $v['type'] != '')
 243                        {
 244                           $f->field((($v['label'] == "") ? $v['name'] : $v['label']));
 245                        $f->html($v['value']);                  
 246                        }
 247                    }
 248                $f->endSection();    
 249                $f->html('</div>');
 250                $f->html('<div style="float: left; width:40%;">');
 251                }      
 252  
 253            if($this->settingsVars['workflowMod'])
 254                {
 255                if($this->settingsVars['workflowComment'])
 256                    $workflow_stuff[$first_id][] = array('name' => 'wflowcomments', 'label' => 'Comments', 'type' => 'textarea', 'def' => '', 'label_alignment' => 'middle', 'label_textalignment' => 'center');
 257                $qf = FormWidget::quickFormGenerator($workflow_stuff[$first_id]) ;
 258                $f2 .= FormWidget::quickForm($qf, '', 'form.noformtagnonsettings.tpl.html');          
 259                $f->html($f2);
 260                }
 261            else
 262                {
 263                $f->section('p1');
 264                foreach($workflow_stuff[$first_id] as $k => $v)
 265                    {
 266                    if ($v['type'] != 'html' && $v['type'] != 'newsection' && $v['type'] != 'linebreak' && $v['type'] != '')
 267                        {
 268                           $f->field((($v['label'] == "") ? $v['name'] : $v['label']));
 269                        $f->html($v['value']);                  
 270                        }
 271                    }
 272                if($this->settingsVars['workflowComment'])
 273                    {
 274                    $f->field('Comments');
 275                    $f->textarea('wflowcomments', '');
 276                    }    
 277                $f->endSection();    
 278                }    
 279      
 280            if($this->settingsVars['workflowCompareDisplay'] == 'column')
 281                {
 282                $f->html('</div>');
 283                $f->html('<div style="clear: both;">&nbsp;</div>');
 284                }
 285                
 286            $f->html('<div style="float: right;margin-right: 20px;">');
 287            
 288            $f->submit('accept', 'Accept');
 289            $f->submit('reject', 'Reject');
 290            
 291            $f->html('</div>');      
 292            }
 293        else
 294            $f->html("<div style='margin-top: 5px;'>There are no items waiting for your approval.<br />&nbsp;</div>");
 295            
 296        $f->html('</div><div style="clear: both;">&nbsp;</div></div>');
 297        
 298        return $f->get();
 299        }
 300  
 301    function onSave()
 302        {
 303        $this->settingsVars['workflowID'] = $this->httpVars['workflowID'];
 304        $this->settingsVars['workflowMod'] = isset($this->httpVars['workflowMod']) ? 1 : 0;
 305        $this->settingsVars['workflowComment'] = isset($this->httpVars['workflowComment']) ? 1 : 0;
 306        $this->settingsVars['workflowCommentQuery'] = $this->httpVars['workflowCommentQuery'];
 307        $this->settingsVars['workflowCompareQuery'] = $this->httpVars['workflowCompareQuery'];
 308        $this->settingsVars['workflowCompareDisplay'] = $this->httpVars['workflowCompareDisplay'];
 309        $this->settingsVars['workflowInterlace'] = $this->httpVars['workflowInterlace'];
 310        $this->saveSettings($this->settingsVars);
 311        }    
 312        
 313    function getConfig()
 314        {
 315        $f = FormWidget::init();
 316        $f->name('worlflow');
 317        $f->html('<div style="background-color: #FFFFFF; padding: 10px;">');
 318        $f->html(Widget::getWizardHelp('Enter the workflow ID from the associated formbuilder to allow entities to be approved.') );
 319        $f->section('p1');
 320        $f->field('Workflow ID');
 321        $f->text('workflowID', @$this->settingsVars['workflowID']);
 322        $f->field('Allow the approver to modify submission?');
 323        $f->checkbox('workflowMod', $this->settingsVars['workflowMod'], "");
 324        $f->field('Allow the approver to add a comment?');
 325        $f->checkbox('workflowComment', $this->settingsVars['workflowComment'], "");
 326        $f->field('');
 327        $f->html('Contruct a query to store the comment, you may use similar syntax to that of the query <br />builder with |comments| representing the comment data.<br />');
 328        $f->textarea('workflowCommentQuery', $this->settingsVars['workflowCommentQuery'], 2, 45);
 329        $f->field('Query to display alongside the submitted data:');
 330        $f->textarea('workflowCompareQuery', $this->settingsVars['workflowCompareQuery'], 2, 45);
 331        $f->field('Query display format:');
 332        $f->radio('workflowCompareDisplay', array('interlace' => 'Interlaced', 'column' => 'Columns'), $this->settingsVars['workflowCompareDisplay']);
 333        $f->field('Interlace offset');
 334        $f->text('workflowInterlace', @$this->settingsVars['workflowInterlace']);
 335        $f->endSection();
 336        $f->html('<div style="margin-top: 10px; float: right;">');
 337        $f->defaultButtons();
 338        $f->html('</div>');
 339        $f->html('<div style="clear: both;">&nbsp;</div>');
 340        $f->html('</div>');
 341        $f->html('<div style="clear: both;">&nbsp;</div>');
 342        return $f->get();
 343        }
 344    }
 345  ?>

title

Description

title

Description

title

Description

title

title

Body