/**
  * build the receiver for a mailinglist
  *
  * @param sfWebRequest $request
  * @return <type>
  */
 public function executeBuildReceiver(sfWebRequest $request) {
     $mailinglist = new Mailinglist();
     $result = UserDataTable::instance()->getAllUserFullname();
     $json_result = $mailinglist->buildReceiver($result);
     $this->renderText('{"result":'.json_encode($json_result).'}');
     return sfView::NONE;
 }
 public function setData() {
     $userSettings = UserSettingTable::instance()->getUserSettingById($this->user_id)->toArray();
     $replayAdress = EmailConfigurationTable::instance()->getEmailConfiguration()->toArray();
     $userLogin = UserLoginTable::instance()->findActiveUserById($this->user_id);
     $userData = UserDataTable::instance()->getUserDataByUserId($this->user_id)->toArray();
     $this->userSettings = $userSettings[0];
     $this->userSettings['systemreplyaddress'] = $replayAdress[0]['systemreplyaddress'];
     $this->userData['username'] = $userLogin[0]->getUsername();
     $this->userData['user_id'] = $userLogin[0]->getId();
     $this->userData['email'] = $userLogin[0]->getEmail();
     $this->userData['firstname'] = $userData[0]['firstname'];
     $this->userData['lastname'] = $userData[0]['lastname'];
 }
    /**
     * Function sends systemmesage, and loads all sender
     * 
     * @param sfWebRequest $request
     * @return <type>
     */
    public function executeSendMail(sfWebRequest $request) {
        $subject = $request->getParameter('subject');
        $type = $request->getParameter('type');
        $content = $request->getParameter('description');
        $decission = $request->getParameter('receiver');
        switch ($decission) {
            case 'ALL':
                $users = UserLoginTable::instance()->getAllUser(-1, -1)->toArray(); // load all user
                break;
            case 'SENDER':
                $users = WorkflowTemplateTable::instance()->getWorkflowSender()->toArray(); // load sender only
                break;
            case 'ONLINE':
                $currentTime = time();
                $fiveMinutes = (1 * 60)*5;
                $fiveMinutesAgo = $currentTime - $fiveMinutes;
                $users = UserDataTable::instance()->getOnlineUser($fiveMinutesAgo)->toArray(); // user which are online for about 5mins^^
                break;
        }
        
        // send messages
        foreach($users as $user) {
            if($decission == 'SENDER') {
               $userData = new UserMailSettings($user['sender_id']);
            }
            elseif ($decission == 'ALL') {
                $userData = new UserMailSettings($user['id']);
            }
            else {
                $userData = new UserMailSettings($user['user_id']);
            }
            $send = new SendMessage();
            $send->sendSystemMail($userData, $subject, $content, $type);
        }


        $this->renderText('{success:true}');
        return sfView::NONE;
    }
 public function getUser($slot_id, $workflowtemplate_id, $slotname, $slotcounter, $templateversion_id) {
     $users = WorkflowSlotUserTable::instance()->getUserBySlotId($slot_id);
     $result = array();
     $a = 0;
     foreach($users as $user) {
         $userlogin = array();
         $userlogin = $user->getUserLogin()->toArray();
         $userData = UserDataTable::instance()->getUserDataByUserId($userlogin[0]['id'])->toArray();
         $result[$a]['user_id'] = $user->getUserId();
         $result[$a]['id'] = $user->getId();
         $result[$a]['plainusername'] = $userData[0]['firstname'] . ' '  . $userData[0]['lastname'] . ' <i>('.$userlogin[0]['username'].')</i>';
         $result[$a]['username'] = '******' . $userlogin[0]['username'] . '</td></tr></table>';
         $result[$a]['slotgroup'] = '#' . $slotcounter . ' : ' . $slotname;
         $result[$a]['templateversion_id'] = $templateversion_id;
         $result[$a]['user'] = $this->getDecission($user, $templateversion_id);
         $a++;
     }
     return $result;
 }
 /**
  * Create new user
  * @param sfWebRequest $request
  * @return <type>
  */
 public function executeSaveUser(sfWebRequest $request) {
     $store = new UserCRUD();
     $result = UserConfigurationTable::instance()->getUserConfiguration()->toArray();
     $data = $request->getPostParameters();
     $data = $store->prepareCreateData($data, $result[0]);
     $user_id = $store->saveLoginDataTab($data);
     UserSettingTable::instance()->updateUserSettingDurationtypeAndDurationlength($data, $user_id);
     UserDataTable::instance()->updateUserAdditinalData($data,$user_id);
     UserSettingTable::instance()->updateUserSetting($data,$user_id);
     $store->addUserAgent($data, $user_id);
     $store->saveWorklfowSettings($data['worklfow'], $user_id, 1);
     $this->renderText('{success:true}');
     return sfView::NONE;
 }