예제 #1
0
 function replace_process($pId, $vars, $create = true)
 {
     $TABLE_NAME = GALAXIA_TABLE_PREFIX . "processes";
     $now = date("U");
     $vars['lastModif'] = $now;
     $vars['normalized_name'] = $this->_normalize_name($vars['name'], $vars['version']);
     foreach ($vars as $key => $value) {
         $vars[$key] = addslashes($value);
     }
     if ($pId) {
         // update mode
         $old_proc = $this->get_process($pId);
         $first = true;
         $query = "update `{$TABLE_NAME}` set";
         foreach ($vars as $key => $value) {
             $que[] = "`{$key}`=?";
             $bindvars[] = $value;
         }
         $query .= implode(',', $que) . " where `pId`=? ";
         $bindvars[] = $pId;
         $this->query($query, $bindvars);
         // Note that if the name is being changed then
         // the directory has to be renamed!
         $oldname = $old_proc['normalized_name'];
         $newname = $vars['normalized_name'];
         if ($newname != $oldname) {
             rename(GALAXIA_PROCESSES . "/{$oldname}", GALAXIA_PROCESSES . "/{$newname}");
         }
         $msg = sprintf(tra('Process %s has been updated'), $vars['name']);
         $this->notify_all(3, $msg);
     } else {
         unset($vars['pId']);
         // insert mode
         $name = $this->_normalize_name($vars['name'], $vars['version']);
         $this->_create_directory_structure($name);
         $query = "insert into `{$TABLE_NAME}`(`";
         $query .= implode('`,`', array_keys($vars)) . "`) values(";
         foreach (array_values($vars) as $value) {
             $que[] = "?";
         }
         $query .= implode(',', $que) . ")";
         $this->query($query, $vars);
         $pId = $this->getOne("select max(pId) from {$TABLE_NAME} where lastModif={$now}");
         // Now automatically add a start and end activity
         // unless importing ($create = false)
         if ($create) {
             $aM = new ActivityManager($this->db);
             $vars1 = array('name' => 'start', 'description' => 'default start activity', 'type' => 'start', 'isInteractive' => 'y', 'isAutoRouted' => 'y');
             $vars2 = array('name' => 'end', 'description' => 'default end activity', 'type' => 'end', 'isInteractive' => 'n', 'isAutoRouted' => 'y');
             $aM->replace_activity($pId, 0, $vars1);
             $aM->replace_activity($pId, 0, $vars2);
         }
         $msg = sprintf(tra('Process %s has been created'), $vars['name']);
         $this->notify_all(4, $msg);
     }
     // Get the id
     return $pId;
 }
예제 #2
0
 function replace_process($p_id, $vars, $create = true)
 {
     $TABLE_NAME = GALAXIA_TABLE_PREFIX . "processes";
     $now = date("U");
     $vars['last_modified'] = $now;
     $vars['normalized_name'] = $this->_normalize_name($vars['procname'], $vars['version']);
     foreach ($vars as $key => $value) {
         $vars[$key] = addslashes($value);
     }
     if ($p_id) {
         // update mode
         $old_proc = $this->get_process($p_id);
         $first = true;
         $query = "update `{$TABLE_NAME}` set";
         foreach ($vars as $key => $value) {
             if (!$first) {
                 $query .= ',';
             }
             if (!is_numeric($value) || strstr($value, '.')) {
                 $value = "'" . $value . "'";
             }
             $query .= " `{$key}`={$value} ";
             $first = false;
         }
         $query .= " where `p_id`={$p_id} ";
         $this->mDb->query($query);
         // Note that if the name is being changed then
         // the directory has to be renamed!
         $oldname = $old_proc['normalized_name'];
         $newname = $vars['normalized_name'];
         if ($newname != $oldname) {
             rename(GALAXIA_PROCESSES . "/{$oldname}", GALAXIA_PROCESSES . "/{$newname}");
             $am = new ActivityManager();
             $am->compile_process_activities($p_id);
         }
         $msg = sprintf(tra('Process %s has been updated'), $vars['procname']);
         $this->notify_all(3, $msg);
     } else {
         unset($vars['p_id']);
         // insert mode
         $name = $this->_normalize_name($vars['procname'], $vars['version']);
         $this->_create_directory_structure($name);
         $first = true;
         $query = "insert into `{$TABLE_NAME}`(";
         foreach (array_keys($vars) as $key) {
             if (!is_numeric($key)) {
                 if (!$first) {
                     $query .= ',';
                 }
                 $query .= "`{$key}`";
                 $first = false;
             }
         }
         $query .= ") values(";
         $first = true;
         foreach ($vars as $key => $value) {
             if (!is_numeric($key)) {
                 if (!$first) {
                     $query .= ',';
                 }
                 if (!is_numeric($value) || strstr($value, '.')) {
                     $value = "'" . $value . "'";
                 }
                 $query .= "{$value}";
                 $first = false;
             }
         }
         $query .= ")";
         $this->mDb->query($query);
         $p_id = $this->mDb->getOne("select max(`p_id`) from `{$TABLE_NAME}` where `last_modified`={$now}");
         // Now automatically add a start and end activity
         // unless importing ($create = false)
         if ($create) {
             $aM = new ActivityManager();
             $vars1 = array('name' => 'start', 'description' => 'default start activity', 'act_type' => 'start', 'is_interactive' => 'y', 'is_auto_routed' => 'y');
             $vars2 = array('name' => 'end', 'description' => 'default end activity', 'act_type' => 'end', 'is_interactive' => 'n', 'is_auto_routed' => 'y');
             $aM->replace_activity($p_id, 0, $vars1);
             $aM->replace_activity($p_id, 0, $vars2);
         }
         $msg = sprintf(tra('Process %s has been created'), $vars['procname']);
         $this->notify_all(4, $msg);
     }
     // Get the id
     return $p_id;
 }