<?php

	if ($this->dmsEncodingInfo) {
		$dms_encoding_profile_id = ($this->dmsEncodingInfo->id)?$this->dmsEncodingInfo->id:0;
		$dms_master_master_id = ($this->dmsEncodingInfo->dms_master_master_id)?$this->dmsEncodingInfo->dms_master_master_id:0;
		$order_type = ($this->dmsEncodingInfo->order_type)?$this->dmsEncodingInfo->order_type:'release';
		$encoding_profile_id = ($this->dmsEncodingInfo->encoding_profile_id)?$this->dmsEncodingInfo->encoding_profile_id:0;
        $required = ($this->dmsEncodingInfo->required) ? $this->dmsEncodingInfo->required : 'Y';
		$width = isset($this->dmsEncodingInfo->width)?$this->dmsEncodingInfo->width:null;
		$height = isset($this->dmsEncodingInfo->height)?$this->dmsEncodingInfo->height:null;
		$frequency = ($this->dmsEncodingInfo->frequency)?$this->dmsEncodingInfo->frequency:44100;
		$channel = ($this->dmsEncodingInfo->channel)?$this->dmsEncodingInfo->channel:'stereo';
		$bitrate = ($this->dmsEncodingInfo->bitrate)?$this->dmsEncodingInfo->bitrate:192000;
		$clip_length = ($this->dmsEncodingInfo->clip_length)?$this->dmsEncodingInfo->clip_length:0;
		$product_type_id = ($this->dmsEncodingInfo->product_type_id)?$this->dmsEncodingInfo->product_type_id:0;
		$id3_tag = ($this->dmsEncodingInfo->id3_tag)?$this->dmsEncodingInfo->id3_tag:'N';
		$extension = ($this->dmsEncodingInfo->extension) ? htmlspecialchars($this->dmsEncodingInfo->extension, ENT_QUOTES, 'UTF-8') : '';
		$vantrix_profile_type = ($this->dmsEncodingInfo->vantrix_profile_type)?$this->dmsEncodingInfo->vantrix_profile_type:'audio';
		$vantrix_profile_id = ($this->dmsEncodingInfo->vantrix_profile_id)?$this->dmsEncodingInfo->vantrix_profile_id:'';
		$filesize_limit = ($this->dmsEncodingInfo->filesize_limit) ? htmlspecialchars($this->dmsEncodingInfo->filesize_limit, ENT_QUOTES, 'UTF-8') : '0';
		$stored_location = ($this->dmsEncodingInfo->stored_location) ? htmlspecialchars($this->dmsEncodingInfo->stored_location, ENT_QUOTES, 'UTF-8') : '';
		$filename = ($this->dmsEncodingInfo->filename) ? htmlspecialchars($this->dmsEncodingInfo->filename, ENT_QUOTES, 'UTF-8') : '';
		$delivery_location = ($this->dmsEncodingInfo->delivery_location) ? htmlspecialchars($this->dmsEncodingInfo->delivery_location, ENT_QUOTES, 'UTF-8') : '';
		$hashcode = ($this->dmsEncodingInfo->hashcode) ? htmlspecialchars($this->dmsEncodingInfo->hashcode, ENT_QUOTES, 'UTF-8') : '';
		$filesize = ($this->dmsEncodingInfo->filesize) ? htmlspecialchars($this->dmsEncodingInfo->filesize, ENT_QUOTES, 'UTF-8') : '';
        $video_image_cat_id = ($this->dmsEncodingInfo->video_image_cat_id)?$this->dmsEncodingInfo->video_image_cat_id:'';
 	}
	if ($this->encodingProfileInfo) {
		$profile_type = ($this->encodingProfileInfo->profile_type)?$this->encodingProfileInfo->profile_type:'metadata';
	}
	$bitrateArr = array('32000','40000','48000','56000','64000','96000','128000','160000','192000','256000','320000');
	$frequencyArr = array('4000','8000','12000','16000','22050','32000','44100','48000');
	$vantrixProfileArr = array("amr_fbr_12.2"=>"amr","awb_12.65"=>"awb","awb_23.05"=>"awb","awb_23.85"=>"awb",
		"mmf_ma2_adpcm"=>"mmf","mmf_ma3_adpcm"=>"mmf","mmf_ma5_adpcm"=>"mmf","pmd_cmx30"=>"pmd","qcp_qcelp13k_half2full"=>"qcp",
		"rmf_ima"=>"rmf","wav_alaw"=>"wav","wav_ima"=>"wav","wav_pcm_16"=>"wav","wav_ulaw"=>"wav");
?>
		<div class="panelHeader">
			<h3>Encoding Profile Setup</h3>
		</div>

		<div class="panelContent">
			<div class="alertError" id="err_msg"></div>
			<form name="add_profile" action="/warehouse/updatedmsencodingprofile" method="post">
			<input type="hidden" id="dms_master_master_id" name="dms_master_master_id" value="<?=$dms_master_master_id?>">
			<input type="hidden" id="dms_encoding_profile_id" name="dms_encoding_profile_id" value="<?=$dms_encoding_profile_id?>">
			<table class="form full">
			<tr><th>Product Type</th>
				<td>
					<select id="product_type_id" name="product_type_id" class="small">
						<?	foreach ($this->product_types as $k => $v) {?>
                            <option value="<?=$k?>" <?=($product_type_id==$k ? 'selected="selected"':'')?>><?=$v?></option>
						<?	} ?>
					</select>
				</td>
			</tr>
			<tr><th>Encoding Order Type</th>
				<td><select id="order_type" name="order_type" class="small">
					<option value="release"<?=($order_type=="release"?' selected="selected"':'')?>>Full Track</option>
					<option value="ringtone"<?=($order_type=="ringtone"?' selected="selected"':'')?>>Tone</option>
					<option value="harddrive"<?=($order_type=="harddrive"?' selected="selected"':'')?>>Harddrive</option>
					</select>
				</td>
			</tr>
			<tr><th>Profile Type</th>
				<td>
                                    <select id="profile_type" name="profile_type" class="small">
                                        <option value="metadata"<?=($profile_type=="metadata"?' selected="selected"':'')?>>Metadata</option>
                                        <option value="audio"<?=($profile_type=="audio"?' selected="selected"':'')?>>Audio</option>
                                        <option value="image"<?=($profile_type=="image"?' selected="selected"':'')?>>Image</option>
                                        <option value="video_image"<?=($profile_type=="video_image"?' selected="selected"':'')?>>Video Image</option>
                                        <option value="video"<?=($profile_type=="video"?' selected="selected"':'')?>>Feature</option>
                                        <option value="trailer"<?=($profile_type=="trailer"?' selected="selected"':'')?>>Trailer</option>
                                        <option value="trigger"
                                            <?php echo ($profile_type == 'trigger' ? ' selected="selected"' : '');?>>
                                            Trigger
                                        </option>
		                    </select>
				</td>
			</tr>
			<tr>
				<th>Format</th>
				<td>
					<select id="encoding_profile_id" name="encoding_profile_id"	class="small">

					</select>
				</td>
			</tr>
            <tr>
                <th>Required</th>
                <td>
                    <select id="required" name="required" class="small">
                        <option <?php echo ($required == 'Y') ? 'selected' : '' ?> value="Y">Yes</option>
                        <option <?php echo ($required == 'N') ? 'selected' : '' ?> value="N">No</option>
                    </select>
                </td>
            </tr>
			<tr id="id3_tag_row">
				<th>Id3 Tag</th>
				<td><select id="id3_tag" name="id3_tag" class="small">
						<option <?php echo ($id3_tag =='Y')? "selected" : "" ?> value="Y">Y</option>
						<option <?php echo ($id3_tag =='N')? "selected" : "" ?> value="N">N</option>
				</select></td>
			</tr>
			<tr>
				<th>Extension</th>
				<td>
					<input type="text" id="extension" name="extension" value="<?php echo $extension; ?>"	class="small" size="4" maxlength="4">
				</td>
			</tr>
			<tr id="clip_row">
			<?php if(!empty($dms_encoding_profile_id)){?>
			<th>Clip Length</th>
			<?php } else { ?>
				<th id="clip_lbl">Add clip</th>
				<?php } ?>
				<td>
					<input type="checkbox" id="clip_length" name="clip_length" value="30" >
					<input type="text" id="clip_length_txt" name="clip_length_txt" class="small" size="4" maxlength="4"	value="<?=(!($clip_length)?$clip_length:'')?>">
				</td>
			</tr>
			<tr id="width_row">
				<th>Width</th>
				<td><input type="text" id="width" name="width" value="<?=$width?>" class="small" size="5" maxlength="5"></td>
			</tr>
			<tr id="height_row">
				<th>Height</th>
				<td><input type="text" id="height" name="height" value="<?=$height?>" class="small" size="5" maxlength="5"></td>
			</tr>
            <tr id="video_image_cat_row">
                <th>Category</th>
                <td>
                    <select id="video_image_cat_id" name="video_image_cat_id" class="small">
                        <option <?php echo ($video_image_cat_id =='2')? "selected" : "" ?> value="2">S2</option>
                        <option <?php echo ($video_image_cat_id =='3')? "selected" : "" ?> value="3">S3</option>
                        <option <?php echo ($video_image_cat_id =='4')? "selected" : "" ?> value="4">S4</option>
                        <option <?php echo ($video_image_cat_id =='5')? "selected" : "" ?> value="5">S5</option>
                        <option <?php echo ($video_image_cat_id =='6')? "selected" : "" ?> value="6">S6</option>
                        <option <?php echo ($video_image_cat_id =='7')? "selected" : "" ?> value="7">S7</option>
                        <option <?php echo ($video_image_cat_id =='8')? "selected" : "" ?> value="8">S8</option>
                        <option <?php echo ($video_image_cat_id =='9')? "selected" : "" ?> value="9">S9</option>
                        <option <?php echo ($video_image_cat_id =='10')? "selected" : "" ?> value="10">S10</option>
                        <option <?php echo ($video_image_cat_id =='11')? "selected" : "" ?> value="11">S11</option>
                    </select>
                </td>
            </tr>

			<tr id="bitrate_row">
				<th>Bitrate (bps)</th>
				<td><select id="bitrate" name="bitrate" class="small">
				<?php if(!empty($bitrateArr)){
					foreach($bitrateArr as $bits){
					?>
						<option value="<?php echo $bits ?>" <?=($bitrate==$bits?' selected="selected"':'')?>><?php echo $bits ?></option>
					<?php } } ?>
				</select></td>
			</tr>
			<tr id="channel_row">
				<th>Channel</th>
				<td><select id="channel" name="channel" class="small">
						<option value="stereo"<?=($channel=='stereo'?' selected="selected"':'')?>>Stereo</option>
						<option value="mono"<?=($channel=='mono'?' selected="selected"':'')?>>Mono</option>
					</select>
				</td>
			</tr>
			<tr id="frequency_row">
				<th>Frequency (Hz)</th>
				<td><select id="frequency" name="frequency" class="small">
				<?php if(!empty($frequencyArr)) {
					foreach ($frequencyArr as $freq) { ?>
						<option value="<?php echo $freq ?>" <?=($frequency==$freq?' selected="selected"':'')?>><?php echo $freq ?></option>
					<?php }
				} ?>
				</select></td>
			</tr>
			<tr id="vantrix_profile_type_row" class="vantrix_profiles">
				<th>Vantrix Profile Type</th>
				<td><select id="vantrix_profile_type" name="vantrix_profile_type" class="small">
						<option <?php echo ($vantrix_profile_type =='audio') ? "selected" : "" ?> value="audio">Audio</option>
						<option <?php echo ($vantrix_profile_type =='video') ? "selected" : "" ?> value="video">Video</option>
				</select></td>
			</tr>
			<tr id="vantrix_profile_id_row" class="vantrix_profiles">
				<th>Vantrix Profile Id <span class="required">*</span></th>
				<td>
				<select style="width:176px" id="vantrix_profile_id" name="vantrix_profile_id" class="small">
					<option value="0">-- Select One --</option>
					<?php foreach ($vantrixProfileArr as $vantrix_profile => $extension){?>
							<option <?php echo ($vantrix_profile_id == $vantrix_profile) ? "selected": ""?> value="<?php echo $vantrix_profile ?>"><?php echo $vantrix_profile ?></option>
					<?php }
						if(!empty($vantrix_profile_id) && !isset($vantrixProfileArr[$vantrix_profile_id])){
							?>
						<option selected value="<?php echo $vantrix_profile_id ?>"><?php echo $vantrix_profile_id ?></option>
						<?php } ?>
					<option value="add_new">Add New</option>
				</select>
				<input type ="text" style="width:170px" id="vantrix_profile_id_txt" name="vantrix_profile_id_txt" class="small"/>
				</td>
			</tr>
			<tr id="filesize_limit_row" class="vantrix_profiles">
				<th>Filesize Limit</th>
				<td>
					<input type="text" id="filesize_limit" name="filesize_limit" value="<?php echo $filesize_limit  ?>"	class="small" size="4" maxlength="4">
				</td>
			</tr>
			<tr id="stored_location_row" class="vantrix_profiles">
				<th>Stored Location</th>
				<td>
					<input type="text" id="stored_location" name="stored_location" value="<?php echo $stored_location ?>" class="small">
				</td>
			</tr>
				<tr id="filename_row" class="tech_manager">
				<th>Filename <span class="required">*</span></th>
				<td>
					<input type="text" size="44" id="filename" name="filename" value="<?php echo $filename ?>" class="small">
				</td>
			</tr>
			<tr id="delivery_location_row" class="tech_manager">
				<th>Delivery Location <span class="required">*</span></th>
				<td>
					<input type="text" size="44" id="delivery_location" name="delivery_location" value="<?php echo $delivery_location ?>" class="small">
				</td>
			</tr>
			<tr id="hashcode_row" class="tech_manager">
				<th>Hashcode</th>
				<td>
					<input type="text" size="44" id="hashcode" name="hashcode" value="<?php echo $hashcode ?>" class="small">
				</td>
			</tr>
			<tr id="filesize_row" class="tech_manager">
				<th>Filesize</th>
				<td>
					<input type="text" size="44" id="filesize" name="filesize" value="<?php echo $filesize ?>" class="small">
				</td>
			</tr>
			</table>
			</form>
			<div class="panelButtons">
				<input type="button" value="Save & Close" id="form_submit_button" class="btn btn-primary btn-sm">
				<input type="button" onclick="modal_overlay.close();" value="Cancel" class="btn btn-default btn-sm">
			</div>
		</div>

        <script type="text/javascript" src="/scripts/oa/warehouse/dmsencodinginfo.js?<?=time()?>"></script>
        <script type="text/json" id="encoding_profiles"><?php echo json_encode($this->encoding_profiles->toArray()) ?></script>
        <script type="text/json" id="edit_profile_type"><?= $profile_type ?></script>
        <script type="text/json" id="edit_order_type"><?= $order_type ?></script>
        <script type="text/json" id="is_wwav_flac"><?php echo in_array($this->encodingProfileInfo->encoding_profile_id, array(13, 80, 324, 365)) ? "true" : "false";?></script>
        <script type="text/json" id="edit_encoding_profile_id"><?php echo $encoding_profile_id; ?></script>
        <script>
            $(document).ready(function() {
                var dmsencodinginfo = new DmsEncodingFunctions();
                dmsencodinginfo.init_profiles(JSON.parse($("#encoding_profiles").html()));
                dmsencodinginfo.show_hide_for_profiletype($("#edit_profile_type").html());
                if($("#is_wwav_flac").html()) {
                    dmsencodinginfo.hide_for_wav_flac() ;
                }
                dmsencodinginfo.encoding_profile_format($("#edit_encoding_profile_id").html());
                dmsencodinginfo.show_vantrix_fields();
                dmsencodinginfo.show_add_clip_option();
                dmsencodinginfo.register_envents();
                dmsencodinginfo.change_order_type($("#edit_order_type").html());

        });

        </script>
