public function updateAction() { $usergroup = Usergroups::findFirst(array('conditions' => 'deleted=0 AND uid = ?1', 'bind' => array(1 => $this->dispatcher->getParam("uid")))); $onspotdates = Onspotdates::find(array()); $environment = $this->config['application']['debug'] ? 'development' : 'production'; $baseUri = $this->config['application'][$environment]['staticBaseUri']; $path = $baseUri . '/backend/' . $this->view->language . '/usergroups/update/'; $this->view->setVar('path', $path); $this->view->setVar('usergroup', $usergroup); $this->view->setVar('onspotdates', $onspotdates); }
public function initialize($entity = null, $options = null) { // In edition the id is hidden if (isset($options['edit']) && $options['edit']) { $uid = new Hidden('uid'); } else { $uid = new Text('uid'); } $this->add($uid); $username = new Text('username', array()); $username->addValidators(array(new PresenceOf(array('message' => 'The name is required')))); $this->add($username); $password = new Password('password', array()); $password->addValidators(array(new PresenceOf(array('message' => 'Password is required')))); $this->add($password); $last_name = new Text('last_name', array()); $last_name->addValidators(array(new PresenceOf(array('message' => 'The lastname is required')))); $this->add($last_name); $first_name = new Text('first_name', array()); $first_name->addValidators(array(new PresenceOf(array('message' => 'The firstname is required')))); $this->add($first_name); $title = new Text('title', array()); $title->addValidators(array(new PresenceOf(array('message' => 'The title is required')))); $this->add($title); $email = new Text('email', array()); $email->addValidators(array(new PresenceOf(array('message' => 'The email is required')), new Email(array('message' => 'The email is not valid')))); $this->add($email); $phone = new Text('phone', array()); $this->add($phone); $address = new Text('address', array()); $this->add($address); $city = new Text('city', array()); $this->add($city); $zip = new Text('zip', array()); $this->add($zip); $company = new Text('company', array()); $this->add($company); $this->add(new Select("profileuid", Profiles::find(array('conditions' => 'deleted=0 AND hidden=0')), array('using' => array('uid', 'title')))); $this->add(new Select("usergroup", Usergroups::find(array('conditions' => 'deleted=0 AND hidden=0')), array('using' => array('uid', 'title')))); $this->add(new Select("userlanguage", Languages::find(array('conditions' => 'deleted=0 AND hidden=0')), array('using' => array('uid', 'title')))); $this->add(new Select('superuser', array('0' => ControllerBase::translate('no'), '1' => ControllerBase::translate('yes')))); }
public function uploadAction() { $time = time(); $this->assets->addJs('js/vendor/addressesInit.js'); $addressfoldersRecords = Feusers::find(array("conditions" => "deleted=0 AND hidden=0 AND usergroup = ?1", "bind" => array(1 => $this->session->get('auth')['usergroup']), "order" => "tstamp DESC")); $usergroups = Usergroups::find(array('conditions' => 'deleted=0 AND cruser_id <> 0')); $this->view->setVar('addressfolders', $addressfoldersRecords); $this->view->setVar('usergroups', $usergroups); $this->view->setVar('filehideshow', ''); $this->view->setVar('maphideshow', 'hidden'); if ($this->request->isPost()) { $this->view->setVar('filehideshow', 'hidden'); $this->view->setVar('maphideshow', ''); if ($this->request->hasFiles() == true) { $mimes = array('application/vnd.ms-excel', 'text/plain', 'text/csv', 'text/tsv'); $fileArray = $this->request->getUploadedFiles(); $file = $fileArray[0]; if (in_array($file->getType(), $mimes)) { $nameArray = explode('.', $file->getName()); $filetype = $nameArray[count($nameArray) - 1]; $tmpFile = '../app/cache/tmp/' . $time . '_' . $file->getName(); $file->moveTo($tmpFile); $row = 0; if (($handle = fopen($tmpFile, "r")) !== FALSE) { $fileRowField = array(); if ($this->request->hasPost('firstRowFieldNames')) { $data[$row] = fgetcsv($handle, 1000, $this->_divider[$this->request->getPost('divider')], $this->_dataWrap[$this->request->getPost('dataFieldWrap')]); $fileRowField = array_values($data[$row]); } else { while ($row < 3) { $data[$row] = fgetcsv($handle, 1000, $this->_divider[$this->request->getPost('divider')], $this->_dataWrap[$this->request->getPost('dataFieldWrap')]); $row++; } for ($i = 0; $i < count($data[0]); $i++) { $fileRowField[] = $data[0][$i] . '<br>' . $data[1][$i] . '<br>' . $data[2][$i]; } } fclose($handle); } else { die('Failed'); } } $this->view->setVar('divider', $this->request->getPost('divider')); $this->view->setVar('dataFieldWrap', $this->request->getPost('dataFieldWrap')); $this->view->setVar('tstamp', $time); $this->view->setVar('firstRowFieldNames', $this->request->hasPost('firstRowFieldNames') ? 1 : 0); $this->view->setVar('filename', $file->getName()); $this->view->setVar('uploadfields', $fileRowField); } else { $time = time(); $row = 0; $insStr = ''; $addressesDBFieldMap = array(1 => 'first_name', 2 => 'last_name', 3 => 'title', 4 => 'salutation', 5 => 'email', 6 => 'company', 7 => 'phone', 8 => 'address', 9 => 'city', 10 => 'zip', 11 => 'userlanguage', 12 => 'gender', 13 => 'region', 14 => 'jobtitle', 15 => 'division', 16 => 'specialization', 18 => 'username', 19 => 'password', 20 => 'image', 21 => 'personellnumber'); $addressesDBFieldTypeMap = array(1 => 'string', 2 => 'string', 3 => 'string', 4 => 'string', 5 => 'string', 6 => 'string', 7 => 'string', 8 => 'string', 9 => 'string', 10 => 'int', 11 => 'int', 12 => 'int', 13 => 'string', 14 => 'string', 15 => 'string', 16 => 'string', 18 => 'string', 19 => 'string', 20 => 'string', 21 => 'string'); $basevals = array('pid' => 0, 'deleted' => 0, 'hidden' => 0, 'profileid' => 0, 'superuser' => 0, 'tstamp' => $time, 'crdate' => $time, 'cruser_id' => $this->session->get('auth')['uid'], 'usergroup' => $this->request->hasPost('usergroup') ? $this->request->getPost('usergroup') : 0, 'onspot' => $this->request->hasPost('onspot') ? 1 : 0); $indexArray = array(); foreach ($this->request->getPost('adressFieldsMap') as $addressFieldIndex => $addressField) { if (intval($addressField) != 0 && !is_nan(intval($addressField))) { $indexArray[$addressFieldIndex] = $addressesDBFieldMap[$addressField]; } } foreach ($addressesDBFieldMap as $fieldIndex => $dbFields) { if (!array_key_exists($dbFields, $indexArray)) { if ($addressesDBFieldTypeMap[$fieldIndex] === 'string') { $basevals[$dbFields] = ''; } else { $basevals[$dbFields] = 0; } } } $tmpFile = '../app/cache/tmp/' . $this->request->getPost('time') . '_' . $this->request->getPost('filename'); if (($handle = fopen($tmpFile, "r")) !== FALSE) { if ($this->request->getPost('firstRowFieldNames') == 1) { $data = fgetcsv($handle, 1000, $this->_divider[$this->request->getPost('divider')], $this->_dataWrap[$this->request->getPost('dataFieldWrap')]); } while (($data = fgetcsv($handle, 1000, $this->_divider[$this->request->getPost('divider')], $this->_dataWrap[$this->request->getPost('dataFieldWrap')])) !== FALSE) { $feuser = new \messetool\Models\Feusers(); $fullname = ''; $imagename = ' '; $imagenameName = ''; $imageNumber = 0; $zipArrStrng = ''; foreach ($indexArray as $index => $indexKey) { if ($indexKey == 'zip') { $ins[$indexKey] = 0; $zipArrStrng = $data[$index]; } elseif ($indexKey == 'first_name') { $fullname = $data[$index]; $imagenameName = $data[$index]; $ins[$indexKey] = $data[$index]; } elseif ($indexKey == 'last_name') { $fullname .= ' ' . $data[$index]; $imagenameName .= '_' . $data[$index]; $ins[$indexKey] = $data[$index]; } elseif ($indexKey == 'phone') { $phone = str_replace(array(' ', '+49', '(', ')', '/', '-'), array('', '', '', '', '', ''), $data[$index]); if (substr($phone, 0, 1) == '0') { $phone = '0049' . substr($phone, 1); } else { $phone = '0049' . $phone; } $ins[$indexKey] = $phone; } elseif ($indexKey == 'image') { $imageNumber = $data[$index]; } else { $ins[$indexKey] = $data[$index]; } } $insArray = array_merge($basevals, $ins); $insArray['fullname'] = $fullname; $insArray['image'] = $imageNumber . '_' . str_replace(' ', '_', $imagenameName) . '.jpg'; if ($this->request->hasPost('onspot')) { $insArray['password'] = $this->auth->encryptPassword($insArray['personellnumber']); } $feuser->assign = $insArray; $feuser->save(); $zipArray = explode(',', $zipArrStrng); foreach ($zipArray as $zip) { $lookup = new \messetool\Models\Feuser_zipcodes_lookup(); $lookup->assign(array('uid_local' => $feuser->uid, 'uid_foreign' => $zip)); $lookup->save(); } } fclose($handle); unlink($tmpFile); } $this->response->redirect('backend/' . $this->view->language . '/feusers/'); $this->view->disable(); } } else { $this->view->setVar('divider', ''); $this->view->setVar('dataFieldWrap', ''); $this->view->setVar('tstamp', ''); $this->view->setVar('filename', ''); $this->view->setVar('firstRowFieldNames', ''); $this->view->setVar('uploadfields', array()); } }