function getAssigned($queue_id = 0)
 {
     if ($queue_id == 0) {
         $queue_id = $this->_queueId;
     }
     if (empty($queue_id)) {
         return FALSE;
     }
     $query = db_select('maestro_queue', 'a');
     $query->addField('a', 'process_id');
     $query->condition('a.id', $queue_id, '=');
     $rec = $query->execute()->fetchObject();
     $processid = $rec->process_id;
     $assigned = array();
     $query = db_select('maestro_production_assignments', 'a');
     $query->fields('a', array('assign_type', 'assign_id', 'process_variable'));
     $query->condition('a.task_id', $queue_id, '=');
     $res = $query->execute();
     foreach ($res as $rec) {
         if ($rec->assign_type == MaestroAssignmentTypes::USER) {
             $type = MaestroAssignmentTypes::getStatusLabel(MaestroAssignmentTypes::USER);
             if ($rec->process_variable == 0) {
                 $user = user_load($rec->assign_id);
                 $assigned[$type['name']][] = $user->name;
             } else {
                 $q2 = db_select('maestro_process_variables', 'a');
                 $q2->addField('a', 'variable_value');
                 $q2->condition('a.process_id', $processid, '=');
                 $q2->condition('a.template_variable_id', $rec->process_variable, '=');
                 $q2rec = $q2->execute()->fetchObject();
                 $user = user_load($q2rec->variable_value);
                 $assigned[$type['name']][] = $user->name;
             }
         } elseif ($rec->assign_type == MaestroAssignmentTypes::ROLE) {
             $type = MaestroAssignmentTypes::getStatusLabel(MaestroAssignmentTypes::ROLE);
             if ($rec->assign_id > 0) {
                 $query = db_select('role', 'a');
                 $query->addField('a', 'name');
                 $query->condition('a.rid', $rec->assign_id);
                 $role = $query->execute()->fetchObject();
                 $assigned[$type['name']][] = $role->name;
             }
         } elseif ($rec->assign_type == MaestroAssignmentTypes::GROUP) {
             $type = MaestroAssignmentTypes::getStatusLabel(MaestroAssignmentTypes::GROUP);
             if ($rec->assign_id > 0) {
                 $group = og_load($rec->assign_id);
                 $assigned[$type['name']][] = $group->label;
             }
         }
     }
     return $assigned;
 }
 function save()
 {
     if (!drupal_valid_token($this->_security_token, 'maestro_admin')) {
         return array('message' => t('Illegal save attempt.'), 'success' => 0, 'task_id' => $this->_task_id);
     }
     $res = db_select('maestro_template_data', 'a');
     $res->fields('a', array('id', 'task_data'));
     $res->condition('a.id', $this->_task_id, '=');
     $rec = current($res->execute()->fetchAll());
     $types = MaestroAssignmentTypes::getStatusLabel();
     $bys = MaestroAssignmentBy::getStatusLabel();
     $whens = MaestroNotificationTypes::getStatusLabel();
     db_query("DELETE FROM {maestro_template_assignment} WHERE template_data_id=:tdid", array(':tdid' => $this->_task_id));
     if (array_key_exists('assignment', $this->_task_edit_tabs) && $this->_task_edit_tabs['assignment'] == 1) {
         foreach ($types as $type => $opt) {
             foreach ($bys as $by_var => $opt) {
                 if (array_key_exists("assign_ids_{$type}_{$by_var}_1", $_POST)) {
                     foreach ($_POST["assign_ids_{$type}_{$by_var}_1"] as $id) {
                         db_query("INSERT INTO {maestro_template_assignment} (template_data_id, assign_type, assign_by, assign_id) VALUES (:tdid, :type, :by_var, :id)", array(':tdid' => $this->_task_id, ':type' => $type, ':by_var' => $by_var, ':id' => $id));
                     }
                 }
             }
         }
     }
     db_query("DELETE FROM {maestro_template_notification} WHERE template_data_id=:tdid", array(':tdid' => $this->_task_id));
     if (array_key_exists('notification', $this->_task_edit_tabs) && $this->_task_edit_tabs['notification'] == 1) {
         foreach ($types as $type => $opt) {
             foreach ($bys as $by_var => $opt) {
                 foreach ($whens as $when => $opt) {
                     if (array_key_exists("notify_ids_{$type}_{$by_var}_{$when}", $_POST)) {
                         foreach ($_POST["notify_ids_{$type}_{$by_var}_{$when}"] as $id) {
                             db_query("INSERT INTO {maestro_template_notification} (template_data_id, notify_type, notify_by, notify_when, notify_id) VALUES (:tdid, :type, :by_var, :when, :id)", array(':tdid' => $this->_task_id, ':type' => $type, ':by_var' => $by_var, 'when' => $when, ':id' => $id));
                         }
                     }
                 }
             }
         }
         $rec->pre_notify_subject = filter_xss($_POST['pre_notify_subject']);
         $rec->pre_notify_message = filter_xss($_POST['pre_notify_message']);
         $rec->post_notify_subject = filter_xss($_POST['post_notify_subject']);
         $rec->post_notify_message = filter_xss($_POST['post_notify_message']);
         $rec->reminder_subject = filter_xss($_POST['reminder_subject']);
         $rec->reminder_message = filter_xss($_POST['reminder_message']);
         $rec->escalation_subject = filter_xss($_POST['escalation_subject']);
         $rec->escalation_message = filter_xss($_POST['escalation_message']);
         $rec->reminder_interval = filter_xss($_POST['reminder_interval']);
         $rec->escalation_interval = filter_xss($_POST['escalation_interval']);
     }
     if (array_key_exists('optional', $this->_task_edit_tabs) && $this->_task_edit_tabs['optional'] == 1) {
         $optional_parms = array();
         if (array_key_exists('op_var_names', $_POST)) {
             foreach ($_POST['op_var_names'] as $key => $var_name) {
                 $var_name = check_plain($var_name);
                 if ($var_name != '') {
                     $optional_parms[$var_name] = check_plain($_POST['op_var_values'][$key]);
                 }
             }
         }
         $rec->task_data = unserialize($rec->task_data);
         $rec->task_data['optional_parm'] = $optional_parms;
         $rec->task_data = serialize($rec->task_data);
     }
     $rec->taskname = filter_xss($_POST['taskname']);
     $rec->regenerate = FALSE;
     if (array_key_exists('regen', $_POST)) {
         $rec->regenerate = TRUE;
     }
     $rec->regen_all_live_tasks = FALSE;
     if (array_key_exists('regenall', $_POST)) {
         $rec->regen_all_live_tasks = TRUE;
     }
     if ($rec->regenerate) {
         $this->_regen_flag = TRUE;
         if ($rec->regen_all_live_tasks == 1) {
             $this->_regen_mode = t(MaestroRegenerationFlag::getStatusLabel(MaestroRegenerationFlag::REGENERATE_ON_PLUS_ALL_LIVE));
         } else {
             $this->_regen_mode = t(MaestroRegenerationFlag::getStatusLabel(MaestroRegenerationFlag::REGENERATE_ON));
         }
     } else {
         if ($rec->regen_all_live_tasks) {
             $this->_regen_flag = TRUE;
             $this->_regen_mode = t(MaestroRegenerationFlag::getStatusLabel(MaestroRegenerationFlag::REGENERATE_ALL_LIVE_ON));
         } else {
             $this->_regen_mode = MaestroRegenerationFlag::REGENERATE_OFF;
             $this->_regen_flag = FALSE;
         }
     }
     if (array_key_exists('showindetail', $_POST)) {
         $rec->show_in_detail = TRUE;
     } else {
         $rec->show_in_detail = FALSE;
     }
     drupal_write_record('maestro_template_data', $rec, array('id'));
     $formatted_task_title = theme('maestro_workflow_task_title', array('tdid' => $this->_task_id, 'taskname' => $rec->taskname, 'regen_flag' => $this->_regen_flag, 'regen_mode' => $this->_regen_mode));
     return array('task_id' => $this->_task_id, 'success' => '1', 'task_title' => $formatted_task_title);
 }