<?php
//Yii::import('ext.krichtexteditor.KRichTextEditor');
/* @var $this ProductResourceController */
/* @var $model ProductResource */
/* @var $form CActiveForm */
?>

<div id="form_wrapper">

<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'resource-form',
	'enableAjaxValidation'=>false,
	'htmlOptions' => array(

        'enctype' => 'multipart/form-data',

    ),
)); ?>

<div id="row">
  <fieldset id="current">
    <legend><strong><?php if($model->isNewRecord) echo "New ProductResource"; else echo "Update ProductResource"; ?></strong><br>
  </legend><table width="800" cellspacing="0" cellpadding="5" border="0">
    <tbody><tr>
      <td width="126"><?php echo $form->labelEx($model,'resource_type_id'); ?><br>
       </td>
      <td width="654">&nbsp;&nbsp;
      	<?php echo $form->dropDownList($model,'resource_type_id',ResourceType::getResourceType(),array('style'=>'width:150px')); ?> 
		<?php echo $form->error($model,'resource_type_id'); ?></td>
    </tr>
    <tr>
      <td><?php echo $form->labelEx($model,'resource_title'); ?></td>
      <td>&nbsp;&nbsp;
       <?php echo $form->textField($model,'resource_title',array('size'=>20,'maxlength'=>255)); ?>
		<?php echo $form->error($model,'resource_title'); ?>
        </td>
    </tr>
    <tr>
      <td><?php echo $form->labelEx($model,'source_file'); ?></td>
      <td>&nbsp;&nbsp;
        <?php echo $form->fileField($model,'source_file'); ?>
		<?php echo $form->error($model,'source_file'); ?>
		
		<?php if(!$model->isNewRecord){ ?>

        <?php echo CHtml::link($model->source_file,Yii::app()->request->getBaseUrl(true).'/media/resources/'.$model->source_file); ?>

        <?php } ?>
		
		</td>
    </tr>
    <tr>
      <td valign="top" align="left"><?php echo $form->labelEx($model,'description'); ?></td>
      <td>&nbsp;&nbsp;<?php echo $form->textArea($model,'description',array('class'=>'ckeditor', 'cols'=>'80', 'id'=>'editor4', 'rows'=>'10')); ?>
       	<?php echo $form->error($model,'description'); ?>
        </td>
    </tr>
    <tr>
      <td><?php echo $form->labelEx($model,'user_group_id'); ?></td>
      <td>&nbsp;&nbsp;
           	<?php echo $form->dropDownList($model,'user_group_id',UserGroup::getGroups(),
											 array(
												'style'=>'width:150px',
												'prompt'=>'Select user group',
												'ajax' => array(
												'type'=>'POST',
												'url'=>CController::createUrl('ProductResource/updateProductGroup'), 
												//'update'=>'#ProductResource_product_group_id',
												'data'=>array('user_group_id'=>'js:this.value'), 
												'success'=>'js:function(data){
													$("#ProductResource_product_group_id").html(data)
													$("#ProductResource_product_category_id").html("<option value=\"\">Select category</option>")
													$("#ProductResource_product_id").html("<option value=\"\">Select category</option>")
													}'
            ))); ?>
			<?php echo $form->error($model,'user_group_id');?>
       </td>
    </tr>
    <tr>
      <td><?php echo $form->labelEx($model,'product_group_id'); ?></td>
      <td>&nbsp;&nbsp;
        <?php echo $form->dropDownList($model,'product_group_id',ProductGroup::getProductGroup($model->user_group_id),array(
												'style'=>'width:150px',
												'prompt'=>'Select product group',
												'ajax' => array(
												'type'=>'POST',
												'url'=>CController::createUrl('ProductResource/updateProductCategory'), 
												//'update'=>'#ProductResource_product_category_id',
												'data'=>array(
															  'user_group_id'=>'js:$("#ProductResource_user_group_id :selected").val()', 
															  'product_group_id'=>'js:this.value'
															  ), 
												'success'=>'js:function(data){
													$("#ProductResource_product_category_id").html(data)
													$("#ProductResource_product_id").html("<option value=\"\">Select product</option>")
													}'
																		  ))); ?>
		<?php echo $form->error($model,'product_group_id'); ?></td>
    </tr>
    <tr>
      <td><?php echo $form->labelEx($model,'product_category_id'); ?></td>
      <td>&nbsp;&nbsp;
        <?php  echo $form->dropDownList($model,'product_category_id',ProductCategory::getProductCategory($model->user_group_id,$model->product_group_id),array(
												'style'=>'width:150px',
												'prompt'=>'Select category',
												'ajax' => array(
												'type'=>'POST',
												'url'=>CController::createUrl('ProductResource/updateProduct'), 
												'update'=>'#ProductResource_product_id',
												'data'=>array(
															  'user_group_id'=>'js:$("#ProductResource_user_group_id :selected").val()',  
															  'product_group_id'=>'js:$("#ProductResource_product_group_id  :selected").val()',  
															  'product_category_id'=>'js:this.value'),  
												
																			 ))); ?>
		<?php echo $form->error($model,'product_category_id'); ?></td>
    </tr>
    <tr>
      <td><?php echo $form->labelEx($model,'product_id'); ?></td>
      <td>&nbsp;&nbsp;
        <?php echo $form->dropDownList($model,'product_id',Product::getProduct($model->user_group_id,$model->product_group_id,$model->product_category_id),array('style'=>'width:150px',
																		 'prompt'=>'Select product',)); ?>
		<?php echo $form->error($model,'product_id'); ?></td>
    </tr>
    
    <tr>
      <td align="right">&nbsp;</td>
      <td>&nbsp;&nbsp;&nbsp;<?php echo CHtml::submitButton($model->isNewRecord ? 'Submit' : 'Save'); ?></td>
    </tr>
  </tbody></table>
  </fieldset>
</div>

<?php $this->endWidget(); ?>

</div><!-- form -->
