public function createCountry($name)
 {
     $tmp = new Country();
     $tmp->name = $name;
     $tmp->save();
     return $tmp;
 }
 public function postCountry()
 {
     $posted = Input::get();
     $country = new Country();
     $country->country_name = $posted['country_name'];
     $country->category_id = $posted['category_id'];
     $country->category_name = $posted['category_name'];
     $country->save();
     return Redirect::back()->with('success', 'Country has been created');
 }
Example #3
0
 function newcountry($data)
 {
     if ($data['name']) {
         $newcountry = new Country();
         $newcountry->name = sqlite_escape_string($data['name']);
         $newcountry->save();
         return true;
     } else {
         return false;
     }
 }
Example #4
0
 public function actionCreate()
 {
     $model = new Country();
     if (isset($_POST['Country'])) {
         $model->attributes = $_POST['Country'];
         if ($model->validate() && $model->save()) {
             $this->redirect(array('index'));
         }
     }
     $statusOptions = array(0 => Yii::t('common', 'Disabled'), 1 => Yii::t('common', 'Enabled'));
     $yesNoOptions = array(0 => Yii::t('common', 'No'), 1 => Yii::t('common', 'Yes'));
     $this->render('create', array('model' => $model, 'statusOptions' => $statusOptions, 'yesNoOptions' => $yesNoOptions));
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Country();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Country'])) {
         $model->attributes = $_POST['Country'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }
 /**
  * Add Country check
  */
 public function add_check()
 {
     $validator = Validator::make(Input::all(), Country::$rulesAdd);
     if (!$validator->fails()) {
         $country = new Country(Input::all());
         if ($country->save()) {
             return Redirect::route('country_list', $country->id)->with('mSuccess', 'Le pays a bien été modifié');
         } else {
             return Redirect::route('country_add')->with('mError', 'Impossible de créer ce pays')->withInput();
         }
     } else {
         return Redirect::route('country_add')->with('mError', 'Il y a des erreurs')->withErrors($validator->messages())->withInput();
     }
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function postCountryCreate()
 {
     // Declare the rules for the form validation
     $rules = array('country' => 'required');
     // Validate the inputs
     $validator = Validator::make(Input::all(), $rules);
     // Check if the form validates with success
     if ($validator->passes()) {
         // Get the inputs, with some exceptions
         $inputs = Input::except('csrf_token');
         $this->country->country = $inputs['country'];
         $this->country->save();
         // Was the role created?
         if ($this->country->id) {
             // Redirect to the new role page
             return Redirect::to('admin/countries/' . $this->country->id . '/edit')->with('success', Lang::get('admin/countries/messages.create.success'));
         }
         // Redirect to the new country page
         return Redirect::to('admin/countries/create')->with('error', Lang::get('admin/countries/messages.create.error'));
     }
     // Form validation failed
     return Redirect::to('admin/countries/create')->withInput()->withErrors($validator);
 }
Example #8
0
 public static function check($_cpt, $_shrt)
 {
     $country = Country::model()->find('short=:shrt', array(':shrt' => $_shrt));
     if ($country !== null) {
         return $country->getPrimaryKey();
     }
     $country = new Country();
     $country->attributes = array('caption' => $_cpt, 'short' => $_shrt);
     if ($country->save()) {
         return $country->getPrimaryKey();
     }
     return 1;
     //false;
 }
 /**
  * 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      ConnectionInterface $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(ConnectionInterface $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 corresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         if ($this->aCountry !== null) {
             if ($this->aCountry->isModified() || $this->aCountry->isNew()) {
                 $affectedRows += $this->aCountry->save($con);
             }
             $this->setCountry($this->aCountry);
         }
         if ($this->aCurrency !== null) {
             if ($this->aCurrency->isModified() || $this->aCurrency->isNew()) {
                 $affectedRows += $this->aCurrency->save($con);
             }
             $this->setCurrency($this->aCurrency);
         }
         if ($this->isNew() || $this->isModified()) {
             // persist changes
             if ($this->isNew()) {
                 $this->doInsert($con);
             } else {
                 $this->doUpdate($con);
             }
             $affectedRows += 1;
             $this->resetModified();
         }
         if ($this->googleshoppingProductSynchronisationsScheduledForDeletion !== null) {
             if (!$this->googleshoppingProductSynchronisationsScheduledForDeletion->isEmpty()) {
                 \GoogleShopping\Model\GoogleshoppingProductSynchronisationQuery::create()->filterByPrimaryKeys($this->googleshoppingProductSynchronisationsScheduledForDeletion->getPrimaryKeys(false))->delete($con);
                 $this->googleshoppingProductSynchronisationsScheduledForDeletion = null;
             }
         }
         if ($this->collGoogleshoppingProductSynchronisations !== null) {
             foreach ($this->collGoogleshoppingProductSynchronisations as $referrerFK) {
                 if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         $this->alreadyInSave = false;
     }
     return $affectedRows;
 }
 public function actionCreateOrg()
 {
     $org = Organization::model()->count();
     if ($org == 0) {
         $this->layout = 'installation_layout';
         $model = new Organization();
         $user = new User();
         $auth_assign = new AuthAssignment();
         // Uncomment the following line if AJAX validation is needed
         $this->performAjaxValidation($model);
         if (isset($_POST['Organization']['organization_name']) && !empty($_POST['Organization']['phone']) && !empty($_POST['Organization']['email'])) {
             $country_model = new Country();
             $country_model->name = $_POST['Organization']['country'];
             $country_model->save();
             $state_model = new State();
             $state_model->state_name = $_POST['Organization']['state'];
             $state_model->country_id = $country_model->id;
             $state_model->save();
             $city_model = new City();
             $city_model->city_name = $_POST['Organization']['city'];
             $city_model->country_id = $country_model->id;
             $city_model->state_id = $state_model->state_id;
             $city_model->save();
             $model->attributes = $_POST['Organization'];
             $model->organization_created_by = 1;
             $model->organization_creation_date = new CDbExpression('NOW()');
             $model->city = $city_model->city_id;
             $model->state = $state_model->state_id;
             $model->country = $country_model->id;
             if ($model->save(false)) {
                 $user->user_organization_email_id = $model->email;
                 $user->user_password = md5($model->email . $model->email);
                 $user->user_type = 'admin';
                 $user->user_created_by = 1;
                 $user->user_creation_date = new CDbExpression('NOW()');
                 $user->user_organization_id = $model->organization_id;
                 $user->save();
                 $auth_assign->itemname = 'SuperAdmin';
                 $auth_assign->userid = $user->user_id;
                 $auth_assign->save(false);
                 $this->redirect(array('redirectLogin'));
             }
         }
         $this->render('create_org', array('model' => $model));
     } else {
         Yii::app()->user->logout();
         $this->redirect(array('login'));
     }
 }
 public function actionCreate()
 {
     $model = new Country();
     if (isset($_POST['Country'])) {
         $model->setAttributes($_POST['Country']);
         if ($model->save()) {
             if (Yii::app()->getRequest()->getIsAjaxRequest()) {
                 Yii::app()->end();
             } else {
                 $this->redirect(array('view', 'id' => $model->country_id));
             }
         }
     }
     $this->render('create', array('model' => $model));
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Country();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Country'])) {
         $model->attributes = $_POST['Country'];
         $model->created_on = date('Y-m-d');
         $model->created_by = Yii::app()->user->id;
         if ($model->save()) {
             Yii::app()->user->setFlash('success', 'Saved successfully');
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }
Example #13
0
 public function agregar()
 {
     $data = array();
     if ($_POST) {
         $pais = new Country(elements(array('pais'), $_POST));
         if ($pais->is_valid()) {
             $pais->save();
             $this->session->set_flashdata('msg', '<div class="success">El pais se guardó correctamente.</div>');
             redirect('paises');
         } else {
             $data['errors'] = $pais->errors;
         }
     }
     $data['titulo'] = "Agregar pais";
     $data['action'] = "paises/agregar";
     $this->template->write_view('content', 'paises/agregar', $data);
     $this->template->render();
 }
 public function save($id = null)
 {
     if ($this->perm->can_create == 'y') {
         if ($_POST) {
             $save = new Country();
             if ($_POST['id'] == '') {
                 $_POST['created_by'] = $this->user->id;
             } else {
                 $_POST['updated_by'] = $this->user->id;
             }
             $save->from_array($_POST);
             $save->save();
             $action = $_POST['id'] > 0 ? 'UPDATE' : 'CREATE';
             save_logs($this->menu_id, $action, $save->id, $action . ' ' . $save->country_name . ' Country');
         }
     }
     redirect("admin/" . $this->modules_name);
 }
 /**
  * Add a new country
  */
 public function actionCreate()
 {
     // Check Access
     checkAccessThrowException('op_country_addpages');
     $model = new Country();
     if (isset($_POST['Country'])) {
         $model->attributes = $_POST['Country'];
         if ($model->save()) {
             fok(at('Country Created.'));
             alog(at("Created Country Record '{name}'.", array('{name}' => $model->name)));
             $this->redirect(array('country/index'));
         }
     }
     // Add Breadcrumb
     $this->addBreadCrumb(at('Creating New Country'));
     $this->title[] = at('Creating New Country Record');
     // Display form
     $this->render('form', array('model' => $model));
 }
 protected function getCountries()
 {
     $xe = $this->web->get(sfConfig::get('app_source_countries'), null, array('Cache-Control' => 'no-cache'));
     $doc = new DOMDocument();
     // It's rare you'll have valid XHTML, suppress any errors- it'll do its best.
     @$doc->loadhtml($xe->getResponseText());
     $xpath = new DOMXPath($doc);
     foreach ($xpath->query('/html/body//form//select[@name="From"]')->item(0)->getElementsByTagName('option') as $option) {
         $currency = Doctrine::getTable('Currency')->findOneByCode($option->getAttribute('value'));
         $name = substr($option->textContent, 0, strpos($option->textContent, ','));
         if ($currency instanceof Currency && !empty($name)) {
             $country = Doctrine::getTable('Country')->findOneByName($name);
             if (!$country instanceof Country) {
                 $country = new Country();
                 $country->setName($name);
             }
             $country->Currencies[] = $currency;
             $country->save();
         }
     }
 }
Example #17
0
 private function createProxies()
 {
     $json = $this->loadProxyJson();
     foreach ($json as $entry) {
         $country = Country::findFirst(array("code = '{$entry->country}'"));
         if (!$country) {
             $country = new Country();
             $country->code = strtoupper($entry->country);
             $country->name = $entry->country;
             $country->save();
         }
         $proxy = Proxy::findFirst(array("address = '{$entry->url}'"));
         if (!$proxy) {
             $proxy = new Proxy();
             $proxy->countryId = $country->id;
             $proxy->address = $entry->url;
             $proxy->save();
             echo '<br />Proxy created: ' . $entry->url;
         } else {
             echo '<br />Proxy exists...';
         }
     }
 }
Example #18
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     if ($this->CanAccess('create')) {
         $model = new Country();
         // Uncomment the following line if AJAX validation is needed
         // $this->performAjaxValidation($model);
         if (isset($_POST['Country'])) {
             $model->attributes = $_POST['Country'];
             if ($model->CanUpdate() && $model->save()) {
                 // if AJAX request , we should not redirect the browser
                 if (!Yii::app()->request->isAjaxRequest) {
                     $this->redirect(array('view', 'id' => $model->id));
                 } else {
                     // UNCOMMENT THIS IF YOU WANT TO RETURN ID OF THE NEWLY CREATED
                     // OBJECT (USEFUL WHEN CREATING NEW OBJECTS VIA AJAX AND INFO ABOUT
                     // THEN NEWLY CREATED OBJECT MUST BE SENT TO THE BROWSER)
                     // echo CJSON::encode(array('error' => '', 'id' => $model->id));
                     // die();
                 }
             }
         }
         if (!Yii::app()->request->isAjaxRequest) {
             $this->render('create', array('model' => $model));
             // IF YOU NEED DIFFERENT RENDERING FOR AJAX AND NON-AJAX CALLS,
             // USE THIS LINE AND DELETE THE LINE ABOVE
             // $this->render('create', array('model' => $model, 'ajaxRendering' => false));
         } else {
             throw new CHttpException(400, Yii::t('app', 'Bad request. The request cannot be fulfilled.'));
             // IF YOU NEED DIFFERENT RENDERING FOR AJAX AND NON-AJAX CALLS,
             // USE THIS LINE AND DELETE THE LINE ABOVE
             // $this->renderPartial('create', array('model' => $model, 'ajaxRendering' => true));
         }
     } else {
         throw new CHttpException(405, Yii::t('app', 'You do not have permissions to access this page.'));
     }
 }
Example #19
0
<p>
The education system or terms in China is similar as Japan and Korea. The higher education system or terms is similar as U.S.A.
</p>
<p>
School education of China includes preschool, primary school, secondary school, high school and university at both the undergraduate and postgraduate level.
</p>
<p>
The following is the school age requirement and the fixed school terms at different levels.
Kindergartens take children above three years old with a term of three school years.
Primary and Junior high schools provide a total of nine years of compulsory education.Primary school is usually six years and junior high school is usually three years, or just nine years inclusive of both primary and junior schooling in some areas. School age for primary schools is usually six and 13 for secondary schools.
</p>
<p>
School age for common Senior High schools is 15 or 16, with a term of three school years, secondary vocational schools usually provide three or four years education and technical schools provide three years education.
</p>
');
    $country->save();
    //
    //  $country = new Country();
    //  $country->setName('Singapo');
    //  $country->setImage('modules/site/assets/images/singapo.jpg');
    //  $country->setBannerImage('modules/site/assets/images/singapo_banner.jpg');
    //  $country->setContent('
    //<h2>Educational System of Korea</h2>
    //<p>Education in Singapore is managed by the Ministry of Education (MOE), which controls the development and administration of state schools receiving government funding, but also has an advisory and supervisory role in respect of private schools. For both private and state schools, there are variations in the extent of autonomy in their curriculum, scope of government aid and funding, tuition burden on the students, and admission policy.
    //</p>
    //<p>
    //Education spending usually makes up about 20 percent of the annual national budget, which subsidises state education and government-assisted private education for Singaporean citizens and funds the Edusave programme, the costs for which are significantly higher for non-citizens. In 2000 the Compulsory Education Act codified compulsory education for children of primary school age (excepting those with disabilities), and made it a criminal offence for parents to fail to enroll their children in school and ensure their regular attendance. Exemptions are allowed for homeschooling or full-time religious institutions, but parents must apply for exemption from the Ministry of Education and meet a minimum benchmark.</p>
    //');
    //  $country->save();
    //
    //  $country = new Country();
Example #20
0
 /**
  * Creates a product based on the data entered in the "new" action
  */
 public function createAction()
 {
     if (!parent::isValidRequest(new CountryValidation())) {
         return parent::redirect('country/new');
     }
     try {
         $code = trim($this->request->get('code'));
         $existingCountry = Country::findFirst(array('conditions' => 'code = ?0', 'bind' => array($code)));
         if ($existingCountry) {
             $this->flash->notice('Country with code <b>' . $code . '</b> address allready exists.');
             return parent::redirect('country/new');
         } else {
             $country = new Country();
             $country->code = $code;
             $country->name = trim($this->request->get('name'));
             $country->save();
             $this->flash->success('Country created succesfully.');
         }
     } catch (Exception $ex) {
         $this->flash->error('An error occured when trying to create the new Country.');
     }
     return $this->redirect('country');
     #$this->view->disable();
 }
Example #21
0
    $content = isset($_POST["content"]) ? $_POST["content"] : null;
    if (empty($content)) {
        Message::register(new Message(Message::DANGER, i18n(array("en" => "content is required.", "zh" => "请填写content"))));
        $error_flag = true;
    }
    /// proceed submission
    // proceed for $name
    $object->setName($name);
    // proceed for $image
    $object->setImage($image);
    // proceed for $banner_image
    $object->setBannerImage($banner_image);
    // proceed for $content
    $object->setContent($content);
    if ($error_flag == false) {
        if ($object->save()) {
            Message::register(new Message(Message::SUCCESS, i18n(array("en" => "Record saved", "zh" => "记录保存成功"))));
            HTML::forwardBackToReferer();
        } else {
            Message::register(new Message(Message::DANGER, i18n(array("en" => "Record failed to save", "zh" => "记录保存失败"))));
        }
    }
}
$html = new HTML();
$html->renderOut('core/backend/html_header', array('title' => i18n(array('en' => 'Create Country', 'zh' => 'Create 留学国家'))));
$html->output('<div id="wrapper">');
$html->renderOut('core/backend/header');
$html->renderOut('destination/backend/country_create', array('object' => $object));
$html->output('</div>');
$html->renderOut('core/backend/html_footer');
exit;
 protected function processAeucLabelTaxIncExc($is_option_active)
 {
     $countries = Country::getCountries((int) Context::getContext()->language->id, true);
     foreach ($countries as $id_country => $country_row) {
         $country = new Country($id_country);
         $country->display_tax_label = (bool) $is_option_active;
         $country->save();
     }
     Configuration::updateValue('AEUC_LABEL_TAX_INC_EXC', (bool) $is_option_active);
 }
 public function actionEditableCreator()
 {
     if (isset($_POST['Country'])) {
         $model = new Country();
         $model->attributes = $_POST['Country'];
         if ($model->save()) {
             echo CJSON::encode($model->getAttributes());
         } else {
             $errors = array_map(function ($v) {
                 return join(', ', $v);
             }, $model->getErrors());
             echo CJSON::encode(array('errors' => $errors));
         }
     } else {
         throw new CHttpException(400, 'Invalid request');
     }
 }
<?php

include 'admin-config.php';
$country_id = $country_name = $country_status = $error = "";
if (strlen(Request::post("submit"))) {
    $country_id = Request::post("country_id");
    $country_name = Request::post("country_name");
    $country_status = Validation::getStautsTinyVal(Request::post("active"));
    $countryObj = new Country();
    $countryObj->set("country_id", $country_id);
    $countryObj->set("country_name", $country_name);
    $countryObj->set("country_status", $country_status);
    if ($countryObj->save()) {
        General::redirectUrl("country.php");
    } else {
        $error = "Country Name alreday exist !";
    }
}
include 'header.php';
include 'sitebar.php';
?>
<div class="ch-container">
    <div class="row">

        <div id="content" class="col-lg-10 col-sm-10">
            <!-- content starts -->
            <div>
                <ul class="breadcrumb">
                    <li>
                        <a href="country.php">Home</a>
                    </li>
 /**
  * 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      ConnectionInterface $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(ConnectionInterface $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 corresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         if ($this->aCustomerTitle !== null) {
             if ($this->aCustomerTitle->isModified() || $this->aCustomerTitle->isNew()) {
                 $affectedRows += $this->aCustomerTitle->save($con);
             }
             $this->setCustomerTitle($this->aCustomerTitle);
         }
         if ($this->aCountry !== null) {
             if ($this->aCountry->isModified() || $this->aCountry->isNew()) {
                 $affectedRows += $this->aCountry->save($con);
             }
             $this->setCountry($this->aCountry);
         }
         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 #26
0
 private function updatesimple($typic, $grtype, $result, &$info)
 {
     if ($typic == 2) {
         $sql = "SELECT a.id AS p_id, a.ckey AS p_key, a.cname AS p_name , a.lid AS p_lid " . " FROM tmp_xml a WHERE a.user="******" AND a.ctype=" . $typic;
     } else {
         $sql = "SELECT a.id AS p_id, a.ckey AS p_key, a.cname AS p_name , a.lid AS p_lid," . " b.id AS g_id, b.ckey AS  g_key, b.cname AS g_name, b.lid as g_lid " . " FROM tmp_xml a LEFT JOIN  tmp_xml b ON a.cgr=b.ckey AND b.user="******" AND b.ctype=" . $grtype . " WHERE a.user="******" AND a.ctype=" . $typic;
     }
     $recs = Yii::app()->db->createCommand($sql)->query();
     //we got the records for tmp_xml table
     $i = 0;
     $j = 0;
     $jj = 0;
     if (count($recs) > 0) {
         foreach ($recs as $value) {
             $doprod = 0;
             $doprodid = 0;
             $edid = 0;
             if ($value['p_lid'] === null) {
                 if ($result[$value['p_id']] === null) {
                     $doprod = -1;
                     $doprodid = 1;
                 } else {
                     $edid = (int) $result[$value['p_id']];
                     if ($edid > 0) {
                         $doprodid = 2;
                         $doprod = $edid;
                     } else {
                         $doprod = -1;
                         $doprodid = 1;
                     }
                 }
             } else {
                 if ($result[$value['p_id']] === null) {
                     $doprod = $value['p_lid'];
                 } else {
                     $edid = $result[$value['p_id']];
                     if ($edid > 0) {
                         $doprodid = 3;
                         $doprod = $edid;
                     } else {
                         $doprod = -1;
                         $doprodid = 4;
                     }
                 }
             }
             $grid = 0;
             if ($doprod < 0) {
                 if ($typic != 2) {
                     if ($value['g_lid'] === null) {
                         if ($typic == 0) {
                             $prodid = ProductgroupId::model()->findByPk(array('ckey' => $value['g_key'], 'db' => 1));
                         } else {
                             $prodid = CountryId::model()->findByPk(array('ckey' => $value['g_key'], 'db' => 1));
                         }
                         if ($prodid === null) {
                             if ($typic == 0) {
                                 $group = new ProductGroup();
                                 $group->tnam = $value['g_name'];
                                 $group->save();
                                 $grid = $group->ckey;
                                 $groupid = new ProductgroupId();
                             } else {
                                 $group = new Country();
                                 $group->name = $value['g_name'];
                                 $group->save();
                                 $grid = $group->id;
                                 $groupid = new CountryId();
                             }
                             $groupid->ckey = $value['g_key'];
                             $groupid->db = 1;
                             $groupid->id = $grid;
                             $groupid->save();
                             $i++;
                         } else {
                             $grid = $prodid->id;
                         }
                     } else {
                         $grid = $value['g_lid'];
                     }
                 } else {
                     $grid = 1;
                 }
                 if ($grid > 0) {
                     if ($typic == 0) {
                         $prod = new Product();
                         $prod->tnam = $value['p_name'];
                         $prod->cgr = $grid;
                         $it = TmpXml::model()->find('ctype=:ctype AND ckey=:ckey AND user=:user', array(':ctype' => 10, ':ckey' => $value['p_key'], ':user' => Yii::app()->user->uid));
                         if ($it) {
                             $prod->it = (int) $it->cname;
                         }
                         $prod->save();
                         $grid = $prod->ckey;
                     } else {
                         if ($typic == 1) {
                             $prod = new Client();
                             $prod->name = $value['p_name'];
                             $prod->country_id = $grid;
                             $prod->save();
                             $grid = $prod->id;
                             $this->updateprop($value['p_key'], $grid);
                             $this->updatebank($value['p_key'], $grid);
                         } else {
                             $prod = new Department();
                             $prod->name = $value['p_name'];
                             $prod->save();
                             $grid = $prod->id;
                             $this->updatebank($value['p_key'], $grid, 0);
                         }
                     }
                     $j++;
                     if ($doprodid == 1) {
                         if ($typic == 0) {
                             $prodid = new ProductId();
                         } else {
                             if ($typic == 1) {
                                 $prodid = new ClientId();
                             } else {
                                 $prodid = new DepartmentId();
                             }
                         }
                         $prodid->ckey = $value['p_key'];
                         $prodid->db = 1;
                         $prodid->id = $grid;
                         $prodid->save();
                     } else {
                         if ($typic == 0) {
                             $prodid = ProductId::model()->findByPk(array('ckey' => $value['p_key'], 'db' => 1));
                         } else {
                             if ($typic == 1) {
                                 $prodid = ClientId::model()->findByPk(array('ckey' => $value['p_key'], 'db' => 1));
                             } else {
                                 $prodid = DepartmentId::model()->findByPk(array('ckey' => $value['p_key'], 'db' => 1));
                             }
                         }
                         if (!($prodid === null)) {
                             $prodid->id = $grid;
                             $prodid->save();
                         }
                     }
                 }
             }
             if ($doprodid == 2) {
                 if ($typic == 0) {
                     $prodid = new ProductId();
                 } else {
                     if ($typic == 1) {
                         $prodid = new ClientId();
                     } else {
                         $prodid = new DepartmentId();
                     }
                 }
                 $prodid->ckey = $value['p_key'];
                 $prodid->db = 1;
                 $prodid->id = $edid;
                 $prodid->save();
             } else {
                 if ($doprodid == 3) {
                     if ($typic == 0) {
                         $prodid = ProductId::model()->findByPk(array('ckey' => $value['p_key'], 'db' => 1));
                     } else {
                         if ($typic == 1) {
                             $prodid = ClientId::model()->findByPk(array('ckey' => $value['p_key'], 'db' => 1));
                         } else {
                             $prodid = DepartmentId::model()->findByPk(array('ckey' => $value['p_key'], 'db' => 1));
                         }
                     }
                     if (!($prodid === null)) {
                         $prodid->id = $edid;
                         $prodid->save();
                     }
                 }
             }
             if ($doprod > 0) {
                 if ($typic == 0) {
                     $prod = Product::model()->findByPk($doprod);
                     if (!($prod === null)) {
                         if ($prod->tnam != $value['p_name']) {
                             $prod->tnam = $value['p_name'];
                             $prod->save();
                             $jj = 0;
                         }
                     }
                 } else {
                     if ($typic == 1) {
                         $prod = Client::model()->findByPk($doprod);
                         if (!($prod === null)) {
                             if ($prod->name != $value['p_name']) {
                                 $prod->name = $value['p_name'];
                                 $prod->save();
                                 $jj = 0;
                             }
                             $this->updateprop($value['p_key'], $prod->id);
                             $this->updatebank($value['p_key'], $prod->id);
                         }
                     } else {
                         if (!($prop = DepartmentProp::model()->findByPk(array('id' => $doprod, '_key' => 'stop')))) {
                             $prod = Department::model()->findByPk($doprod);
                             if (!($prod === null)) {
                                 if ($prod->name != $value['p_name']) {
                                     $prod->name = $value['p_name'];
                                     $prod->save();
                                     $jj = 0;
                                 }
                             }
                             $this->updatebank($value['p_key'], $doprod, 0);
                         }
                     }
                 }
             }
         }
     }
     if ($typic == 0) {
         $info[] = 'Создано новых групп товаров:' . $i;
         $info[] = 'Создано новых товаров:' . $j;
         $info[] = 'Обновлено товаров:' . $jj;
     } else {
         if ($typic == 1) {
             $info[] = 'Создано новых групп клиентов:' . $i;
             $info[] = 'Создано новых клиентов:' . $j;
             $info[] = 'Обновлено клиентов:' . $jj;
         } else {
             $info[] = 'Создано новых фирм:' . $j;
             $info[] = 'Обновлено фирм:' . $jj;
         }
     }
     return;
 }
 public function actionUpload()
 {
     parent::actionUpload();
     $folder = $_SERVER['DOCUMENT_ROOT'] . Yii::app()->request->baseUrl . '/upload/';
     // folder for uploaded files
     $file = $folder . basename($_FILES['uploadfile']['name']);
     if (move_uploaded_file($_FILES['uploadfile']['tmp_name'], $file)) {
         $row = 0;
         if (($handle = fopen($file, "r")) !== FALSE) {
             while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
                 if ($row > 0) {
                     $model = Country::model()->findByPk((int) $data[0]);
                     if ($model === null) {
                         $model = new Country();
                     }
                     $model->countryid = (int) $data[0];
                     $model->countrycode = $data[1];
                     $model->countryname = $data[2];
                     $model->recordstatus = (int) $data[3];
                     try {
                         if (!$model->save()) {
                             $this->messages = $this->messages . Catalogsys::model()->getcatalog(' upload error at ' . $data[0]);
                         }
                     } catch (Exception $e) {
                         $this->messages = $this->messages . $e->getMessage();
                     }
                 }
                 $row++;
             }
         } else {
             $this->messages = $this->messages . ' memory or harddisk full';
         }
         fclose($handle);
     } else {
         $this->messages = $this->messages . ' check your directory permission';
     }
     if ($this->messages == '') {
         $this->messages = 'success';
     }
     echo $this->messages;
 }
Example #28
0
 public function executeProcessForm(sfWebRequest $request)
 {
     ini_set('display_errors', false);
     $data = array();
     $util = new Util();
     $data = $request->getPostParameter("data");
     $q = Doctrine_Query::create()->update('Movie')->set('name_org', '?', $data['name_org'])->set('director', '?', $data['director'])->set('rating', '?', $data['rating'])->set('plot', '?', $data['plot'])->where('id = ?', $data['id']);
     $rows = $q->execute();
     $movie = Doctrine::getTable('Movie')->findOneById($data['id']);
     //year
     if ($data['year'] == "") {
         $movie->Year = NULL;
         $movie->save();
     } else {
         $year_object = Doctrine::getTable('Year')->findOneByName($data['year']);
         if ($year_object == NULL) {
             $year_object = new Year();
             $year_object->name = $data['year'];
             $year_object->coverMo = $util->changePathSeparators($util->makePath(array(sfConfig::get('app_years_rel'), '_' . $util->unformatName($data['year']) . '.jpg')));
             $year_object->coverMu = $util->changePathSeparators($util->makePath(array(sfConfig::get('app_years_rel'), $util->unformatName($data['year']) . '.jpg')));
             $year_object->save();
         }
         $movie->Year = $year_object;
         $movie->save();
     }
     //country
     if ($data['country'] == "") {
         $movie->Country = NULL;
         $movie->save();
     } else {
         $country_object = Doctrine::getTable('Country')->findOneByName($data['country']);
         if ($country_object == NULL) {
             $country_object = new Country();
             $country_object->name = $data['country'];
             $country_object->cover = $util->changePathSeparators($util->makePath(array(sfConfig::get('app_countries_rel'), $util->unformatName($data['country']) . '.png')));
             $country_object->save();
         }
         $movie->Country = $country_object;
         $movie->save();
     }
     //genres
     foreach ($data['genres'] as $genre) {
         $genre_object = Doctrine::getTable('Genre')->findOneByName($genre);
         //if this not exist let's create it
         if ($genre_object == NULL) {
             $genre_object = new Genre();
             $genre_object->name = $genre;
             $genre_object->cover = $util->changePathSeparators($util->makePath(array(sfConfig::get('app_genres_rel'), $util->unformatName($genre) . '.jpg')));
             $genre_object->Movies[] = $movie;
             $genre_object->save();
         } else {
             //check if the movie already has such Genre
             $found = false;
             foreach ($movie['MovieGenre'] as $db_genre) {
                 if ($db_genre['Genre']['name'] == $genre) {
                     $found = true;
                 }
             }
             if ($found == false) {
                 $genre_object->Movies[] = $movie;
                 $genre_object->save();
             }
         }
     }
     //removing the db genres which are not in the request
     foreach ($movie['MovieGenre'] as $db_genre) {
         $found2 = false;
         foreach ($data['genres'] as $genre) {
             if ($db_genre['Genre']['name'] == $genre) {
                 $found2 = true;
             }
         }
         if ($found2 == false) {
             $q = Doctrine_Query::create()->delete('MovieGenre')->addWhere('movie_id = ?', $db_genre['movie_id'])->andWhere('genre_id = ?', $db_genre['genre_id']);
             $deleted = $q->execute();
         }
     }
     //actors
     foreach ($data['actors'] as $item) {
         $actor_object = Doctrine::getTable('Actor')->findOneByName($item['actor']);
         //if this not exist let's create it
         if ($actor_object == NULL) {
             $actor_object = new Actor();
             $actor_object->name = $item['actor'];
             $actor_object->cover = $util->changePathSeparators($util->makePath(array(sfConfig::get('app_actors_rel'), $util->unformatName($item['actor']) . '.jpg')));
             $actor_object->Movies[] = $movie;
             $actor_object->save();
             $q = Doctrine_Query::create()->from('MovieActor ma')->where('ma.movie_id = ?', $movie['id'])->andWhere('ma.actor_id = ?', $actor_object['id']);
             $movie_actor = $q->execute();
             $movie_actor[0]->role = $item['character'];
             $movie_actor[0]->save();
         } else {
             //check if the movie already has such Actor
             $found = false;
             foreach ($movie['MovieActor'] as $db_actor) {
                 if ($db_actor['Actor']['name'] == $item['actor']) {
                     $found = true;
                 }
             }
             if ($found == false) {
                 $movie_actor = new MovieActor();
                 $movie_actor->actor_id = $actor_object['id'];
                 $movie_actor->movie_id = $movie['id'];
                 $movie_actor->role = $item['character'];
                 $movie_actor->save();
             }
         }
     }
     //removing the db genres which are not in the request
     foreach ($movie['MovieActor'] as $db_actor) {
         $found2 = false;
         foreach ($data['actors'] as $item) {
             if ($db_actor['Actor']['name'] == $item['actor']) {
                 $found2 = true;
             }
         }
         if ($found2 == false) {
             $q = Doctrine_Query::create()->delete('MovieActor')->addWhere('movie_id = ?', $db_actor['movie_id'])->andWhere('actor_id = ?', $db_actor['actor_id']);
         }
         $deleted = $q->execute();
     }
     //var_dump($data);
     exit;
 }
 public function actionNewcountry()
 {
     if (isset($_POST['Country'])) {
         $obj = new Country();
         $obj->attributes = $_POST['Country'];
         $obj->active = 1;
         $obj->sort_order = 10;
         if ($obj->validate()) {
             if ($obj->save()) {
                 echo "success";
             } else {
                 echo _xls_convert_errors_display(_xls_convert_errors($obj->getErrors()));
             }
         } else {
             echo _xls_convert_errors_display(_xls_convert_errors($obj->getErrors()));
         }
     }
 }
Example #30
0
 public function setUpCountry()
 {
     $country = new Country();
     $country->id = 1;
     $country->country_name = 'Abkhazia';
     $country->flag_url = 'flags/Abkhazia.png';
     $country->save();
 }