<?php  
  $baseUrl = Yii::app()->baseUrl; 
  $cs = Yii::app()->getClientScript();
  $cs->registerScriptFile($baseUrl.'/js/ckeditor/ckeditor.js');
  $cs->registerCssFile($baseUrl.'/css/bootstrap.css');
?>
<div class="main_content">
<div class="innercontent_outerbox">
  <?php
    foreach(Yii::app()->user->getFlashes() as $key => $message) {
        echo '<div class="flash-' . $key . '">' . $message . "</div>\n";
    }
    ?>
  <h1>Submit a Paper </h1>
  <div class="row">
    <div class="span8">
    <?php $form=$this->beginWidget('CActiveForm', array(
			'id'=>'paper-form',
			'enableAjaxValidation'=>false,
			'htmlOptions' => array('class'=>'form-horizontal','enctype' => 'multipart/form-data'),
		)); ?>
            <?php //echo $form->errorSummary($model); ?>
        <fieldset>
          <div class="control-group">
          <?php echo $form->labelEx($model,'title_of_the_paper',array('class'=>'control-label')); ?>
            <div class="controls">
            <?php echo $form->textField($model,'title_of_the_paper',array('class'=>'input-xlarge','maxlength'=>255)); ?>
		<?php echo $form->error($model,'title_of_the_paper'); ?>
            </div>
          </div>
          <div class="control-group">
          <?php echo $form->labelEx($model,'region_id',array('class'=>'control-label')); ?>
            <div class="controls">
              <?php  echo $form->dropDownList($model,'region_id',Country::getCountry(),array('style'=>'width:250px;','prompt'=>'Select country')); ?>
		<?php echo $form->error($model,'region_id'); ?>
            </div>
          </div>
          <div class="control-group">
          <?php echo $form->labelEx($model,'Product category *',array('class'=>'control-label')); ?>
            <div class="controls">
              <?php echo $form->dropDownList($model,'user_group_id',UserGroup::getGroups(),
											 array(
												'style'=>'width:250px',
												'prompt'=>'Select category',
												/*'ajax' => array(
												'type'=>'POST',
												'url'=>CController::createUrl('site/updateProductGroup'), 
												//'update'=>'#Product_product_group_id',
												'data'=>array('user_group_id'=>'js:this.value'), 
												'success'=>'js:function(data){
													$("#Paper_product_group_id").html(data)
													$("#Paper_product_category_id").html("<option value=\"\">Select category</option>")
													$("#Paper_product_id").html("<option value=\"\">Select product</option>")
													}'
            )*/)); ?>
		<?php echo $form->error($model,'user_group_id'); ?>
            </div>
          </div>
            <?php/*
          <div class="control-group">
          <?php echo $form->labelEx($model,'product_group_id',array('class'=>'control-label')); ?>
            <div class="controls">
              <?php echo $form->dropDownList($model,'product_group_id',ProductGroup::getProductGroup($model->user_group_id),array(
												'style'=>'width:250px',
												'prompt'=>'Select group',
												'ajax' => array(
												'type'=>'POST',
												'url'=>CController::createUrl('site/updateProductCategory'), 
												'data'=>array(
															  'user_group_id'=>'js:$("#Paper_user_group_id :selected").val()',  
															  'product_group_id'=>'js:this.value'
															  ),  
												'success'=>'js:function(data){
													$("#Paper_product_category_id").html(data)
													$("#Paper_product_category_id").change();
													$("#Paper_product_id").html("<option value=\"\">Select product</option>")
													}'
																		  ))); ?> 
		<?php echo $form->error($model,'product_group_id'); ?>
            </div>
          </div>
          <div class="control-group">
          <?php echo $form->labelEx($model,'product_category_id',array('class'=>'control-label')); ?>
            <div class="controls">
              <?php  echo $form->dropDownList($model,'product_category_id',ProductCategory::getProductCategory($model->user_group_id,$model->product_group_id),array(
												'style'=>'width:250px',
												'prompt'=>'Select category',
												'ajax' => array(
												'type'=>'POST',
												'url'=>CController::createUrl('site/updateProduct'), 
												'update'=>'#Paper_product_id',
												'data'=>array(
															  'user_group_id'=>'js:$("#Paper_user_group_id :selected").val()',  
															  'product_group_id'=>'js:$("#Paper_product_group_id :selected").val()',  
															  'product_category_id'=>'js:this.value'
															  ),  
																		  ))); ?>
		<?php echo $form->error($model,'product_category_id'); ?>
            </div>
          </div>
            
            
          <div class="control-group">
          <?php echo $form->labelEx($model,'product_id',array('class'=>'control-label')); ?>
            <div class="controls">
              <?php echo $form->dropDownList($model,'product_id',Product::getProduct($model->user_group_id,$model->product_group_id,$model->product_category_id),array('style'=>'width:250px', 'prompt'=>'Select product',)); ?>
		<?php echo $form->error($model,'product_id'); ?>
            </div>
          </div>
            */?>
          <div class="control-group">
          <?php echo $form->labelEx($model,'industry_id',array('class'=>'control-label')); ?>
            <div class="controls">
              <?php echo $form->dropDownList($model,'industry_id',Industry::getIndustry(),array('style'=>'width:250px', 'prompt'=>'Select industry',)); ?>
		<?php echo $form->error($model,'industry_id'); ?>
            </div>
          </div>
          <div class="control-group">
          <?php echo $form->labelEx($model,'year',array('class'=>'control-label')); ?>
            <div class="controls">
              <?php for($i=date('Y');$i>=1990;$i--) $years[$i]=$i; ?>
        <?php echo $form->dropDownList($model,'year',$years,array('style'=>'width:250px', 'prompt'=>'Select Year',)); ?>
		<?php echo $form->error($model,'year'); ?>
            </div>
          </div>
          <div class="control-group">
          <?php echo $form->labelEx($model,'filename',array('class'=>'control-label')); ?>
            <div class="controls">
              <?php echo $form->fileField($model,'filename'); ?>
		<?php echo $form->error($model,'filename'); ?>
		<?php if(!$model->isNewRecord): ?>
        <?php echo CHtml::link($model->filename,Yii::app()->baseUrl.'/media/paper/'.$model->filename); ?>
        <?php endif; ?>
            </div>
          </div>
          <div class="control-group">
          <?php echo $form->labelEx($model,'content',array('class'=>'control-label')); ?>
            <div class="controls">
            <?php echo $form->textArea($model,'content',array('class'=>'ckeditor','cols'=>"80",'rows'=>"10")); ?>
		<?php echo $form->error($model,'content'); ?>
            </div>
          </div>
          <div class="control-group">
            <label class="control-label" for="input01"></label>
            <div class="controls">
            <?php echo CHtml::submitButton($model->isNewRecord ? 'Submit' : 'Save',array('class'=>'btn btn-success','rel'=>"tooltip")); ?>
            </div>
          </div>
        </fieldset>
      <?php $this->endWidget(); ?>
    </div>
  </div>
</div>
<?php echo $this->renderPartial('_bottom_common_user_product_group'); ?>