Example #1
0
 /**
  * @param string $emailAddress
  * @return mixed if true integer otherwise null
  */
 public static function saveEmailAddress($emailAddress)
 {
     $emailID = null;
     $parseEmail = explode('@', strtolower(trim($emailAddress)));
     if (count($parseEmail) == 2) {
         $domain = Domain::model()->findByAttributes(array('name' => $parseEmail[1]));
         if (!$domain) {
             $domain = new Domain();
             $domain->name = $parseEmail[1];
         }
         if ($domain->save()) {
             $email = new Email();
             $email->username = $parseEmail[0];
             $email->domainID = $domain->ID;
             if ($email->save()) {
                 $emailID = $email->ID;
             } else {
                 if ($domain->isNewRecord) {
                     Domain::model()->deleteByPk($domain->ID);
                 }
             }
         }
     }
     return $emailID;
 }
Example #2
0
 private function saveDomain($domain, $grade, $image)
 {
     $model = new Domain();
     $model->domain = $domain;
     $model->image = $image . '.png';
     $model->grade = $grade;
     $model->save(false);
 }
 public function save()
 {
     try {
         $model = new Domain();
         $this->data->domain->entry = 'dom_' . $this->data->domain->entry;
         $model->setData($this->data->domain);
         $model->save();
         $this->renderPrompt('information', 'OK', "editEntry('{$this->data->domain->entry}');");
     } catch (\Exception $e) {
         $this->renderPrompt('error', $e->getMessage());
     }
 }
 /**
  * Adds a domain to the database
  * 
  * @param string $name The name of the domain
  * @param string type The type of the domain. Can be:<br/>
  * MASTER
  * NATIVE
  * @param int $template_id An optional template ID to be loaded in the domain
  * @return array {result:boolean,error_code:int,error_message:string} A json encoded array containing:
  * result: true if the domain has been created, false otherwise
  * error_code: the code of the error. 0 means no error
  * error_message: the explanation of the error
  */
 public function actionAddDomain($name, $type = Domain::TYPE_MASTER, $template_id = '')
 {
     $result = true;
     $error = array('code' => 0, 'message' => '');
     $domain = new Domain();
     $domain->name = $name;
     $domain->type = $type;
     try {
         if (!$domain->save()) {
             $error['code'] = self::ERROR_VALIDATION_CODE;
             $error['message'] = $domain->getErrors();
             $result = false;
         } else {
             // If there is a template, let's load it and insert:
             if ($template_id != '') {
                 $records = Yii::app()->db->createCommand()->select()->from('zone_templ_records')->where('zone_templ_id = :id', array(':id' => $template_id))->queryAll();
                 $record_results = array();
                 foreach ($records as $record) {
                     $record['name'] = str_replace(array('[ZONE]', '[SERIAL]'), array($name, '1'), $record['name']);
                     $record['content'] = str_replace(array('[ZONE]', '[SERIAL]'), array($name, '1'), $record['content']);
                     $record_results[] = $this->actionAddRecord($name, $record['name'], $record['type'], $record['content'], empty($record['ttl']) ? 3600 : $record['ttl'], empty($record['prio']) ? 0 : $record['prio'], false, false);
                 }
                 $domain->updateSOA();
                 $all_ok = true;
                 foreach ($record_results as $record_result) {
                     if ($record_result['result'] !== true) {
                         $all_ok = false;
                     }
                 }
                 if ($all_ok) {
                     $result = true;
                 } else {
                     $result = false;
                     $error['code'] = self::ERROR_TEMPLATE_CODE;
                     $error['message'] = $record_results;
                 }
             }
         }
     } catch (CDbException $e) {
         if ($e->getCode() == 23000) {
             // Domain already existing
             $error['code'] = self::ERROR_DOMAIN_ALREADY_EXISTING_CODE;
             $error['message'] = "Domain already existing";
         } else {
             $error['code'] = $e->getCode();
             $error['message'] = $e->getMessage();
         }
         $result = false;
     }
     $var = array('error_code' => $error['code'], 'error_message' => $error['message'], 'result' => $result);
     $this->renderText(CJSON::encode($var));
     return $var;
 }
Example #5
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Domain();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Domain'])) {
         $model->attributes = $_POST['Domain'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }
 public function actionAdminView($id)
 {
     $model = DomainSuggestion::model()->findByPk($id);
     if (strcasecmp($model->status, "pending") == 0) {
         if (isset($_POST['button1'])) {
             $model->status = "Accepted";
             $model->description = $_POST['DomainSuggestion']['description'];
             $domainID = $_POST['DomainSuggestion']['Domain'];
             $dom = Domain::model()->findByPk($domainID);
             if (is_null($dom)) {
                 $dom = new Domain();
                 $dom->name = $model->name;
                 $dom->description = $model->description;
                 $dom->need = "Medium";
                 $dom->need_amount = 5;
                 $dom->validator = 5;
                 $dom->save();
             } else {
                 $subDom = new Subdomain();
                 $subDom->need = "Medium";
                 $subDom->name = $model->name;
                 $subDom->description = $model->description;
                 $subDom->validator = 5;
                 $subDom->need_amount = 5;
                 $subDom->domain_id = $dom->id;
                 $subDom->save();
             }
             if ($model->save()) {
                 $this->redirect(array('view', 'id' => $model->suggestion_id));
             }
         }
         if (isset($_POST['button2'])) {
             $model->status = "Rejected";
             if ($model->save()) {
                 $this->redirect(array('view', 'id' => $model->suggestion_id));
             }
         }
         $this->render('adminView', array('model' => $model));
     } else {
         $this->actionView($id);
     }
 }
Example #7
0
 /**
  * Performs the work of inserting or updating the row in the database.
  *
  * If the object is new, it inserts it; otherwise an update is performed.
  * All related objects are also updated in this method.
  *
  * @param PropelPDO $con
  * @return int             The number of rows affected by this insert/update and any referring fk objects' save() operations.
  * @throws PropelException
  * @see        save()
  */
 protected function doSave(PropelPDO $con)
 {
     $affectedRows = 0;
     // initialize var to track total num of affected rows
     if (!$this->alreadyInSave) {
         $this->alreadyInSave = true;
         // We call the save method on the following object(s) if they
         // were passed to this object by their coresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         if ($this->aDomain !== null) {
             if ($this->aDomain->isModified() || $this->aDomain->isNew()) {
                 $affectedRows += $this->aDomain->save($con);
             }
             $this->setDomain($this->aDomain);
         }
         if ($this->aProperty !== null) {
             if ($this->aProperty->isModified() || $this->aProperty->isNew()) {
                 $affectedRows += $this->aProperty->save($con);
             }
             $this->setProperty($this->aProperty);
         }
         if ($this->aUser !== null) {
             if ($this->aUser->isModified() || $this->aUser->isNew()) {
                 $affectedRows += $this->aUser->save($con);
             }
             $this->setUser($this->aUser);
         }
         if ($this->isNew() || $this->isModified()) {
             // persist changes
             if ($this->isNew()) {
                 $this->doInsert($con);
             } else {
                 $this->doUpdate($con);
             }
             $affectedRows += 1;
             $this->resetModified();
         }
         $this->alreadyInSave = false;
     }
     return $affectedRows;
 }
Example #8
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function postStore()
 {
     $input = Input::only('user_id', 'domain', 'sip_server', 'description', 'homepage', 'title', 'theme', 'allow_registration');
     $input['prefix'] = $this->generate_prefix();
     $rules = array('domain' => 'required|domain|unique:domains,domain,NULL,id,deleted_at,NULL', 'sip_server' => 'required|different:domain|unique:domains,sip_server,NULL,id,deleted_at,NULL', 'prefix' => 'unique:domains,prefix');
     $v = Validator::make($input, $rules);
     if ($v->fails()) {
         return Output::push(array('path' => 'domain/add', 'errors' => $v, 'input' => TRUE));
     }
     $domain = new Domain(['id' => md5($input['domain'] . time()), 'user_id' => Auth::user()->status == 2 ? $input['user_id'] : Auth::user()->id, 'domain' => $input['domain'], 'sip_server' => $input['sip_server'], 'prefix' => $input['prefix'], 'allow_registration' => $input['allow_registration'], 'description' => $input['description'], 'title' => $input['title'], 'homepage' => $input['homepage'], 'theme' => $input['theme']]);
     if ($this->_registeredDss($input['sip_server'])) {
         return Output::push(array('path' => 'domain/add', 'messages' => array('fail' => _('We Are Sorry! Domain name for SIP Server (DSS) was registered and Active'))));
     } elseif ($domain->id) {
         $domain->save();
         Event::fire('logger', array(array('domain_add', array('id' => $domain->id, 'domain_name' => $domain->domain), 2)));
         return Output::push(array('path' => 'domain', 'messages' => array('success' => _('You have added domain successfully'))));
     } else {
         return Output::push(array('path' => 'domain/add', 'messages' => array('fail' => _('Fail to add domain')), 'input' => TRUE));
     }
 }
 public function createHandle()
 {
     $pr = DirectoryHelpers::getPagerank(e(Input::get('url')));
     $valid_domain = function ($domain_name) {
         return preg_match("/^([a-z\\d](-*[a-z\\d])*)(\\.([a-z\\d](-*[a-z\\d])*))*\$/i", $domain_name) && preg_match("/^.{1,253}\$/", $domain_name) && preg_match("/^[^\\.]{1,63}(\\.[^\\.]{1,63})*\$/", $domain_name);
         //length of each label
     };
     $format_url = rtrim(str_replace(['http://', 'https://'], '', e(Input::get('url'))), '/');
     if (!$valid_domain($format_url)) {
         Session::put('category_id', e(Input::get('category_id')));
         return Redirect::back()->with('url_error', trans('directory.invalid_url'))->withInput();
     }
     $url_details = parse_url(e(Input::get('url')));
     $final_url = isset($url_details['scheme']) ? $url_details['scheme'] . '://' . $format_url : 'http://' . $format_url;
     Input::merge(array('url' => $final_url));
     $nice_input_names = ['category_id' => trans('directory.select_category'), 'name' => trans('directory.name'), 'url' => trans('directory.url'), 'format_url' => trans('directory.url'), 'description' => trans('directory.description'), 'keywords' => trans('directory.keywords')];
     $rules = ['category_id' => 'not_in:"0"', 'name' => 'required|between:6,260', 'url' => 'required|url|between:6,100|unique:domains', 'description' => 'required|between:200,1000', 'keywords' => 'between:5,255'];
     if (!Auth::check()) {
         $nice_input_names['g-recaptcha-response'] = 'captcha';
         $rules['g-recaptcha-response'] = 'required|recaptcha';
     }
     $coma_replace = function ($string) {
         return str_replace(',', ', ', $string);
     };
     if (strlen(str_replace(' ', '', e(Input::get('description')))) < 200 && Auth::user()->type != User::ADMIN_USER) {
         $attempt = new Attempt();
         $attempt->user_id = Auth::check() ? Auth::user()->id : null;
         $attempt->category_id = (int) e(Input::get('category_id'));
         $attempt->url = 'http://' . $format_url;
         $attempt->name = e(Input::get('name'));
         $attempt->description = $coma_replace(DirectoryHelpers::correctText(e(Input::get('description')), '.'));
         $attempt->keywords = $coma_replace(e(Input::get('keywords')));
         $attempt->save();
         return Redirect::back()->with('error', 'Descrierea este prea scurt&#259;')->withInput();
     }
     $validator = Validator::make(array_map('trim', Input::all()), $rules, [], $nice_input_names);
     if ($validator->fails()) {
         Session::put('category_id', e(Input::get('category_id')));
         return Redirect::back()->withErrors($validator)->withInput();
     }
     $status = Acl::isSuperAdmin() ? 1 : 0;
     $domain = new Domain();
     $domain->category_id = (int) e(Input::get('category_id'));
     $domain->status = $status;
     $domain->name = $coma_replace(e(Input::get('name')));
     $domain->url = 'http://' . $format_url;
     $domain->page_rank = $pr;
     $domain->description = $coma_replace(DirectoryHelpers::correctText(e(Input::get('description')), '.'));
     $domain->keywords = $coma_replace(e(Input::get('keywords')));
     try {
         $domain->thumb = DirectoryHelpers::generateThumb($domain->url);
     } catch (Exception $ex) {
         Log::error($ex->getMessage());
     }
     if ($domain->save()) {
         Acl::addAdmin($domain);
         return Redirect::route('domain.create')->with('success', trans('directory.domain_added'));
     }
     return Redirect::back()->with('error', trans('directory.domain_add_error'));
 }
Example #10
0
<?php

if (PHP_SAPI !== 'cli') {
    die("Testscript may only run in CLI-mode");
}
set_include_path(get_include_path() . PATH_SEPARATOR . '..');
require_once 'Record.php';
require_once 'Domain.php';
$test_domain = mt_rand() . '.example.com';
$test_name = 'record' . mt_rand();
$test_content = '127.0.0.1';
$d = new Domain(array('name' => $test_domain, 'master' => null, 'last_check' => null, 'type' => 'NATIVE', 'notified_serial' => null, 'account' => null));
$d->save();
$d->type = 'MASTER';
$d->save();
$r = new Record(array('name' => $test_name, 'type' => 'A', 'content' => $test_content, 'ttl' => '3600', 'prio' => '0', 'change_date' => date("U")));
$d->records_push($r);
foreach (Record::find('all', array('conditions' => 'name LIKE ' . ActiveRecord::quote($test_name . '%') . ' AND ' . 'content = ' . ActiveRecord::quote($test_content))) as $f) {
    $f->update_attributes(array('name' => $f->name . '1'));
    $f->destroy();
}
$d->destroy();
Example #11
0
 /**
  * Add
  */
 public function executeAdd()
 {
     if ($this->isGET()) {
         return $this->renderJson(array("success" => false, "info" => "POST only."));
     } else {
         $name = $this->getRequestParameter('name');
         $domain = new Domain();
         $domain->setName($name);
         $domain->setType($this->template->getType());
         $domain->save();
         foreach ($this->template->getTemplateRecords() as $tr) {
             $record = new Record();
             $record->setDomainId($domain->getId());
             $record->setName(str_replace("%DOMAIN%", $name, $tr->getName()));
             $record->setType($tr->getType());
             if ($tr->getType() == 'SOA') {
                 $content = str_replace("%DOMAIN%", $name, $tr->getContent());
                 $content = str_replace("%SERIAL%", date("Ymd") . "01", $content);
             } else {
                 $content = $tr->getContent();
             }
             $record->setContent($content);
             $record->setTtl($tr->getTtl());
             $record->setPrio($tr->getPrio());
             $record->save();
         }
         return $this->renderJson(array("success" => true, "info" => "Domain added."));
     }
 }
Example #12
0
 /**
  * Updates a domain
  *
  * @param int $intId
  * @param array $arrData
  * @return int The domain ID
  */
 public function do_update($intId, $arrData)
 {
     $domain = null;
     $con = Propel::getConnection();
     if (!$con->beginTransaction()) {
         throw new Exception('Could not start transaction.');
     }
     try {
         $user = $this->requireUser();
         $account = $user->getAccount($con);
         // Validate input data
         $validator = new KickstartValidator();
         $locale = Localizer::getInstance();
         $warnings = $validator->filterErrors($arrData, $this->initFilter($this->filter_basic, $locale));
         if ($warnings) {
             $con->rollBack();
             return array('result' => false, 'warnings' => $warnings);
         }
         $query = DomainQuery::create()->filterByAccount($account);
         if ($intId !== null) {
             $domain = DomainQuery::create()->filterByAccount($account)->findOneById($intId, $con);
             if ($domain === null) {
                 throw new Exception('Domain not found; ID: ' . $intId);
             }
             $query->filterById($intId, Criteria::NOT_EQUAL);
         } else {
             $domain = new Domain();
             $domain->setAccount($account);
         }
         // Check for duplicates
         if ($query->findOneByName($arrData['Name'], $con)) {
             throw new Exception($locale->insert('error.taken', array('value' => '"' . $arrData['Name'] . '"')));
         }
         $domain->fromArray(array_intersect_key($arrData, array('AddressId' => true, 'Name' => true, 'Description' => true, 'Number' => true)));
         $domain->save($con);
         if (!empty($arrData['Properties'])) {
             $domain->setProperties($arrData['Properties'], $con);
         }
     } catch (Exception $e) {
         $con->rollBack();
         throw $e;
     }
     if (!$con->commit()) {
         throw new Exception('Could not commit transaction.');
     }
     return $domain->getId();
 }
Example #13
0
 /**
  * Performs the work of inserting or updating the row in the database.
  *
  * If the object is new, it inserts it; otherwise an update is performed.
  * All related objects are also updated in this method.
  *
  * @param PropelPDO $con
  * @return int             The number of rows affected by this insert/update and any referring fk objects' save() operations.
  * @throws PropelException
  * @see        save()
  */
 protected function doSave(PropelPDO $con)
 {
     $affectedRows = 0;
     // initialize var to track total num of affected rows
     if (!$this->alreadyInSave) {
         $this->alreadyInSave = true;
         // We call the save method on the following object(s) if they
         // were passed to this object by their coresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         if ($this->aAccount !== null) {
             if ($this->aAccount->isModified() || $this->aAccount->isNew()) {
                 $affectedRows += $this->aAccount->save($con);
             }
             $this->setAccount($this->aAccount);
         }
         if ($this->aDomain !== null) {
             if ($this->aDomain->isModified() || $this->aDomain->isNew()) {
                 $affectedRows += $this->aDomain->save($con);
             }
             $this->setDomain($this->aDomain);
         }
         if ($this->isNew() || $this->isModified()) {
             // persist changes
             if ($this->isNew()) {
                 $this->doInsert($con);
             } else {
                 $this->doUpdate($con);
             }
             $affectedRows += 1;
             $this->resetModified();
         }
         if ($this->clockingsRelatedByCreatorIdScheduledForDeletion !== null) {
             if (!$this->clockingsRelatedByCreatorIdScheduledForDeletion->isEmpty()) {
                 foreach ($this->clockingsRelatedByCreatorIdScheduledForDeletion as $clockingRelatedByCreatorId) {
                     // need to save related object because we set the relation to null
                     $clockingRelatedByCreatorId->save($con);
                 }
                 $this->clockingsRelatedByCreatorIdScheduledForDeletion = null;
             }
         }
         if ($this->collClockingsRelatedByCreatorId !== null) {
             foreach ($this->collClockingsRelatedByCreatorId as $referrerFK) {
                 if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         if ($this->clockingsRelatedByUserIdScheduledForDeletion !== null) {
             if (!$this->clockingsRelatedByUserIdScheduledForDeletion->isEmpty()) {
                 ClockingQuery::create()->filterByPrimaryKeys($this->clockingsRelatedByUserIdScheduledForDeletion->getPrimaryKeys(false))->delete($con);
                 $this->clockingsRelatedByUserIdScheduledForDeletion = null;
             }
         }
         if ($this->collClockingsRelatedByUserId !== null) {
             foreach ($this->collClockingsRelatedByUserId as $referrerFK) {
                 if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         if ($this->propertyValuesScheduledForDeletion !== null) {
             if (!$this->propertyValuesScheduledForDeletion->isEmpty()) {
                 foreach ($this->propertyValuesScheduledForDeletion as $propertyValue) {
                     // need to save related object because we set the relation to null
                     $propertyValue->save($con);
                 }
                 $this->propertyValuesScheduledForDeletion = null;
             }
         }
         if ($this->collPropertyValues !== null) {
             foreach ($this->collPropertyValues as $referrerFK) {
                 if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         if ($this->systemLogsScheduledForDeletion !== null) {
             if (!$this->systemLogsScheduledForDeletion->isEmpty()) {
                 foreach ($this->systemLogsScheduledForDeletion as $systemLog) {
                     // need to save related object because we set the relation to null
                     $systemLog->save($con);
                 }
                 $this->systemLogsScheduledForDeletion = null;
             }
         }
         if ($this->collSystemLogs !== null) {
             foreach ($this->collSystemLogs as $referrerFK) {
                 if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         if ($this->transactionsRelatedByCreatorIdScheduledForDeletion !== null) {
             if (!$this->transactionsRelatedByCreatorIdScheduledForDeletion->isEmpty()) {
                 foreach ($this->transactionsRelatedByCreatorIdScheduledForDeletion as $transactionRelatedByCreatorId) {
                     // need to save related object because we set the relation to null
                     $transactionRelatedByCreatorId->save($con);
                 }
                 $this->transactionsRelatedByCreatorIdScheduledForDeletion = null;
             }
         }
         if ($this->collTransactionsRelatedByCreatorId !== null) {
             foreach ($this->collTransactionsRelatedByCreatorId as $referrerFK) {
                 if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         if ($this->transactionsRelatedByUserIdScheduledForDeletion !== null) {
             if (!$this->transactionsRelatedByUserIdScheduledForDeletion->isEmpty()) {
                 TransactionQuery::create()->filterByPrimaryKeys($this->transactionsRelatedByUserIdScheduledForDeletion->getPrimaryKeys(false))->delete($con);
                 $this->transactionsRelatedByUserIdScheduledForDeletion = null;
             }
         }
         if ($this->collTransactionsRelatedByUserId !== null) {
             foreach ($this->collTransactionsRelatedByUserId as $referrerFK) {
                 if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         $this->alreadyInSave = false;
     }
     return $affectedRows;
 }
Example #14
0
 /**
  * Creates a deep copy of a domain and it's associated records.
  */
 public function actionCopy($id)
 {
     $oldmodel = $this->loadModel($id);
     $model = new Domain();
     $model->name = $oldmodel->name;
     $model->master = $oldmodel->master;
     $model->last_check = $oldmodel->last_check;
     $model->type = $oldmodel->type;
     $model->notified_serial = $oldmodel->notified_serial;
     $model->account = $oldmodel->account;
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Domain'])) {
         $model->attributes = $_POST['Domain'];
         if ($model->save()) {
             // copy records
             if ($model->copy_records == 1) {
                 foreach ($oldmodel->records as $or) {
                     $record = new Record();
                     $record->domain_id = $model->id;
                     $record->name = $or->name;
                     $record->type = $or->type;
                     $record->content = $or->content;
                     $record->ttl = $or->ttl;
                     $record->prio = $or->prio;
                     $record->change_date = $or->change_date;
                     $record->save();
                 }
             }
             // copy permissions
             if ($model->copy_permissions == 1) {
                 foreach ($oldmodel->users as $user) {
                     $perm = new DomainUser();
                     $perm->domain_id = $model->id;
                     $perm->user_id = $user->id;
                     $perm->save();
                 }
             }
             Yii::app()->audit->log('Copied domain: ' . $model->id);
             $this->redirect(array('update', 'id' => $model->id));
         }
     }
     $this->render('copy', array('model' => $model));
 }
Example #15
0
 public function domain_add($p)
 {
     //TODO validate domain attributes..
     $d = new Domain(array('name' => $p->name, 'type' => $p->type));
     $d->save();
     return $d->id;
 }
 public function actionuserProfile()
 {
     $model = User::getCurrentUser();
     $promentor = ProjectMentor::getCurrentUser();
     $permentor = PersonalMentor::getCurrentUser();
     $dommentor = DomainMentor::getCurrentUser();
     if (isset($_POST['submit'])) {
         $model->biography = $_POST['biography'];
         $uploadedFile = CUploadedFile::getInstance($model, 'pic_url');
         /*Attach file */
         $fileName = "{$uploadedFile}";
         if ($fileName != null) {
             /*Save file uploaded in the Uploads folder */
             $model->pic_url = '/coplat/images/profileimages/' . $fileName;
             $uploadedFile->saveAs(Yii::getPathOfAlias('webroot') . '/images/profileimages/' . $fileName);
         }
         $model->save(false);
         if ($model->isProMentor == 1) {
             echo $_POST['proHours'];
             $promentor->max_hours = $_POST['proHours'];
             //$promentor->max_projects = $_POST['numProjects'];
             $promentor->save();
             if (isset($_POST['proj'])) {
                 $projs = $_POST['proj'];
                 if (empty($projs)) {
                     echo " No projects selected ";
                 } else {
                     $pro = $_POST['proj'];
                     $curr = Project::model()->findallbysql("SELECT * FROM project WHERE project_mentor_user_id={$model->id}");
                     for ($i = 0; $i < $promentor->max_projects - count($curr); $i++) {
                         $p = Project::model()->findBySql("SELECT * FROM project WHERE title='{$pro[$i]}'");
                         $p->project_mentor_user_id = $model->id;
                         $p->save();
                     }
                 }
             }
         }
         if ($model->isPerMentor == 1) {
             $permentor->max_hours = $_POST['pmenHours'];
             // $permentor->max_mentees = $_POST['numMentees'];
             $permentor->save();
             if (isset($_POST['mentees'])) {
                 $men = $_POST['mentees'];
                 $curr = Mentee::model()->findallbysql("SELECT * FROM mentee WHERE personal_mentor_user_id={$model->id}");
                 for ($i = 0; $i < $permentor->max_mentees - count($curr); $i++) {
                     $m = Mentee::model()->findBySql("SELECT * FROM mentee WHERE user_id={$men[$i]}");
                     $m->personal_mentor_user_id = $model->id;
                     $m->save();
                 }
             }
         }
         if ($model->isDomMentor == 1) {
             $dommentor->max_tickets = $_POST['numTickets'];
             $dommentor->save();
             if (isset($_POST['domainName'])) {
                 $d = new Domain();
                 $d->name = $_POST['domainName'];
                 if (Domain::model()->domainExists($d->name)) {
                     //do nothing
                 } else {
                     $d = new Domain();
                     $ud = new UserDomain();
                     $d->name = $_POST['domainName'];
                     $d->save();
                     $ud->domain_id = $d->id;
                     $ud->user_id = $model->id;
                     $ud->rate = $_POST['ratings'];
                     $ud->save();
                 }
             }
             if (isset($_POST['existDoms'])) {
                 $doms = $_POST['existDoms'];
                 for ($i = 0; $i < count($doms); $i++) {
                     $d = Domain::model()->findBySql("SELECT id FROM domain WHERE name='{$doms[$i]}'");
                     $ud = new UserDomain();
                     $ud->domain_id = $d->id;
                     $ud->user_id = $model->id;
                     $ud->rate = $_POST['ratings'];
                     $ud->save();
                 }
             }
             if (isset($_POST['unrated'])) {
                 $ud = UserDomain::model()->findAllBySql("SELECT * FROM user_domain WHERE rate IS NULL AND user_id={$model->id} ");
                 $ur = $_POST['unrated'];
                 for ($i = 0; $i < count($ur); $i++) {
                     $ud[$i]->rate = $ur[$i];
                     $ud[$i]->save();
                 }
             }
         }
     }
     /** @var User $username */
     $username = Yii::app()->user->name;
     $user = User::model()->find("username=:username", array(':username' => $username));
     $projects = Project::model()->findAllBySql("SELECT title FROM project WHERE project_mentor_user_id={$user->id}");
     $userdoms = UserDomain::model()->findAllBySql("SELECT distinct domain_id FROM user_domain WHERE user_id={$user->id}");
     $Mentees = Mentee::model()->findAllBySql("SELECT user_id FROM mentee WHERE personal_mentor_user_id={$user->id}");
     $Tickets = Ticket::model()->findAllBySql("SELECT * FROM ticket WHERE assign_user_id=:id", array(":id" => $user->id));
     $this->render('userProfile', array('Tickets' => $Tickets, 'user' => $user, 'userdoms' => $userdoms, 'Mentees' => $Mentees, 'projects' => $projects));
 }