<?php $this->load->view('admin/inc/header');?>
<link href="<?php echo base_url('/');?>plupload/js/jquery.plupload.queue/css/jquery.plupload.queue.css" rel="stylesheet">
<link href="<?php echo base_url('/');?>admin_src/css/datepicker.css" rel="stylesheet">
<script type='text/javascript' src="//code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
<script type='text/javascript' src="<?php echo base_url('/');?>admin_src/js/jquery-ui-1.10.3.custom.min.js"></script>
<body>
	
	<?php $this->load->view('admin/inc/nav_top');?>
		
	<div class="container-fluid">
		<div class="row-fluid">
			<?php $this->load->view('admin/inc/nav_main');?>
			<div id="content" class="span10">
			<!-- start: Content -->
			
			<div>
				<hr>
				<ul class="breadcrumb">
					<li>
						<a href="<?php echo site_url('/');?>">Home</a> <span class="divider">/</span>
					</li>
					<li>
						<a href="<?php echo site_url('/');?>admin/members/">Members</a><span class="divider">/</span>
					</li>
                    <li>
						Update Member: <?php echo $title;?>
					</li>
				</ul>
				<hr>
			</div>
			
			<div class="row-fluid sortable">
            
            
				<div class="box span8">
					<div class="box-header">
						<h2><i class="icon-th"></i><span class="break"></span> Update Member: <?php echo $name;?></h2>
						<div class="box-icon">
							<a href="#" class="btn-close"><i class="icon-remove"></i></a>
						</div>
					</div>
					<div class="box-content">
                  	  	<p>
							<form id="member-update" name="member-update" method="post" action="<?php echo site_url('/');?>admin/update_member_do" class="form-horizontal">
                             <fieldset>
    										<input type="hidden" name="member_id"  value="<?php if(isset($member_id)){echo $member_id;}?>">
                                            <input type="hidden" name="autosave" id="autosave"  value="true">
                                            <input type="hidden" name="status" id="status"  value="<?php if(isset($status)){echo $status;}?>">
                                          <div class="control-group">
                                            <label class="control-label" for="title">Title</label>
                                            <div class="controls">
                                                    <input type="text" class="span6" id="name" name="name" placeholder="Member Name" value="<?php if(isset($name)){echo $name;}?>">
                                            </div>
                                          </div>
                                         <div class="control-group">
                                            <label class="control-label" for="abreviation">Abreviation</label>
                                            <div class="controls">
                                                    <input type="text" class="span6" id="abreviation" name="abreviation" placeholder="Member Abreviation" value="<?php if(isset($abreviation)){echo $abreviation;}?>">  
                                            </div>
                                          </div>
                                        
                           				 <div class="control-group">
                                            <label class="control-label" for="title">Contact</label>
                                            <div class="controls">
                                                    <input type="text" class="span6" id="contact" name="contact" placeholder="Member Contact" value="<?php if(isset($contact)){echo $contact;}?>">
                            
                                            </div>
                                          </div>
                                          <div class="control-group">
                                            <label class="control-label" for="email">Email</label>
                                            <div class="controls">
                                                    <input type="text" class="span6" id="email" name="email" placeholder="Member Email" value="<?php if(isset($email)){echo $email;}?>">  
                                            </div>
                                          </div>
                            				
                                         <div class="control-group">
                                            <label class="control-label" for="type">Type</label>
                                            <div class="controls">
                                                  
                                                    <select class="span6" id="type" name="type" >
                                                         <option value="CSO" <?php if($type == 'CSO'){echo 'selected';}?>>CSO</option>
                                                         <option value="NO" <?php if($type == 'NO'){echo 'selected';}?>>NO</option>
                                                         <option value="IO" <?php if($type == 'IO'){echo 'selected';}?>>IO</option>
                                                         <option value="CBO" <?php if($type == 'CBO'){echo 'selected';}?>>CBO</option>
                                                         <option value="STAFF" <?php if($type == 'STAFF'){echo 'selected';}?>>STAFF</option>
                                                         <option value="PAIDUP" <?php if($type == 'PAIDUP'){echo 'selected';}?>>PAIDUP</option> 
                                                         <option value="DONOR" <?php if($type == 'DONOR'){echo 'selected';}?>>DONOR</option>
                                                         <option value="INDUVIDUAL" <?php if($type == 'INDUVIDUAL'){echo 'selected';}?>>INDUVIDUAL</option>
                                                         <option value="PARTNER" <?php if($type == 'PARTNER'){echo 'selected';}?>>PARTNER</option>
                                                     </select>
                                                     
                                                                                                  
                                                  
                                            </div>
                                          </div>
                                          
                            				
                                         <div class="control-group">
                                            <label class="control-label" for="phone">Phone</label>
                                            <div class="controls">
                                                    <input type="text" class="span6" id="phone" name="phone" placeholder="Member Phone" value="<?php if(isset($phone)){echo $phone;}?>">  
                                            </div>
                                          </div>
                                          
                                         <div class="control-group">
                                            <label class="control-label" for="fax">Fax</label>
                                            <div class="controls">
                                                    <input type="text" class="span6" id="fax" name="fax" placeholder="Member Fax" value="<?php if(isset($fax)){echo $fax;}?>">  
                                            </div>
                                          </div>                                          
                                          
                                         <div class="control-group">
                                            <label class="control-label" for="region">Region</label>
                                            <div class="controls">
                                                  
                                                    <select class="span6" id="region" name="region">
                                                        <option value="Caprivi" <?php if($region == 'Caprivi'){echo 'selected';}?>>Caprivi</option>
                                                        <option value="Erongo" <?php if($region == 'Erongo'){echo 'selected';}?>>Erongo</option>
                                                        <option value="Hardap" <?php if($region == 'Hardap'){echo 'selected';}?>>Hardap</option>
                                                        <option value="Karas" <?php if($region == 'Karas'){echo 'selected';}?>>Karas</option>
                                                        <option value="Khomas" <?php if($region == 'Khomas'){echo 'selected';}?>>Khomas</option>
                                                        <option value="Kunene" <?php if($region == 'Kunene'){echo 'selected';}?>>Kunene</option>
                                                        <option value="Ohangwena" <?php if($region == 'Ohangwena'){echo 'selected';}?>>Ohangwena</option>
                                                        <option value="Okavango" <?php if($region == 'Okavango'){echo 'selected';}?>>Okavango</option>
                                                        <option value="Omaheke" <?php if($region == 'Omaheke'){echo 'selected';}?>>Omaheke</option>
                                                        <option value="Omusati" <?php if($region == 'Omusati'){echo 'selected';}?>>Omusati</option>
                                                        <option value="Oshana" <?php if($region == 'Oshana'){echo 'selected';}?>>Oshana</option>
                                                        <option value="Oshikoto" <?php if($region == 'Oshikoto'){echo 'selected';}?>>Oshikoto</option>
                                                        <option value="Otjozondjupa" <?php if($region == 'Otjozondjupa'){echo 'selected';}?>>Otjozondjupa</option>
                                                   </select> 
                                            </div>
                                          </div>                                           
                                          
                                         <div class="control-group">
                                            <label class="control-label" for="city">City</label>
                                            <div class="controls">
                                                    <input type="text" class="span6" id="city" name="city" placeholder="City" value="<?php if(isset($city)){echo $city;}?>">  
                                            </div>
                                          </div>                                             
                                          
                                          <div class="control-group" id="redactor_content_msg">
                                                <label class="control-label" for="redactor_content">Member Address:</label>
                                                <div class="controls">
                                                    
                                                    <textarea id="redactor_content" name="address" style="display:block"><?php if(isset($address)){echo $address;}?></textarea>
                                                </div>
                                           </div>
                                         
                                         <div class="control-group">
                                            <label class="control-label" for="website">Website</label>
                                            <div class="controls">
                                                    <input type="text" class="span6" id="website" name="website" placeholder="Website" value="<?php if(isset($website)){echo $website;}?>">  
                                            </div>
                                          </div> 
                                         
                                            <!-- <div class="control-group">
                                                    <label class="control-label" for="pub_date">Publish date</label>
                                                    <div class="controls">
                                                             <div class="input-append date" id="dob" data-date="1985-10-19" data-date-format="yyyy-mm-dd" data-date-viewmode="years">
                                                              <input type="text"  name="pub_date" id="pub_date" value="<?php if (isset($review)){echo date('Y-m-d',strtotime($review));}else{ echo '1985-10-19';}?>" readonly>
                                                              <span class="add-on"><i class="icon-calendar"></i></span>
                                                            </div> 
                                                            <span class="help-block" style="font-size:11px">Select the date the member is published</span>
                                                    </div> 
                                               </div>-->
       
                                          
                                          <div id="result_msg"></div>
                                          <button type="submit" class="btn btn-inverse btn pull-right" id="butt">Update Member</button>
                                           
                               </fieldset> 
                             </form>
		             	</p>                  
                  </div>
				</div>
                <div class="box span4">
					<!--<div class="box-header">
						<h2><i class="icon-th"></i><span class="break"></span>Member Documents</h2>
						<div class="box-icon">
							<a href="#" class="btn-close"><i class="icon-remove"></i></a>
						</div>
					</div>
					<div class="box-content">
                  	  	<p>
							List of documents attached to <em><?php if(isset($title)){echo $title;} ?></em>.</p>
                        <div id="member_docs">   
                            <?php //$this->admin_model->get_member_docs($member_id);?>
                        </div>
                        <div id="uploader" style="display:none">
                            <p>You browser doesn't have Flash, Silverlight, Gears, BrowserPlus or HTML5 support.</p>
                        </div>
		             	 
                        <div id="doc_msg"></div>
                        <a onClick="$('#uploader').slideToggle();" class="btn btn-inverse"><i class="fa-icon-plus-sign"></i> Add Documents</a>                  
                  </div>-->
				</div>
                
                
			</div>   
			
			<hr>
			
			<div class="row-fluid">
				
				
				
			</div>
			
			<hr>
			

			
			<!-- end: Content -->
			</div><!--/#content.span10-->
		</div><!--/fluid-row-->
				
		 <div class="modal hide fade" id="modal-doc-delete">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal">×</button>
				<h3>Delete Document</h3>
			</div>
			<div class="modal-body">
				<p>The document will be removed from the Member. This process is not reversible.</p>
			</div>
			<div class="modal-footer">
				<a href="#" class="btn" data-dismiss="modal">Close</a>
				<a href="#" class="btn btn-primary">Delete Document</a>
			</div>
		</div>
        
        
        <div class="modal hide fade" id="modal-doc-update">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal">×</button>
				<h3>Update Document</h3>
			</div>
			<div class="modal-body loading" id="doc_update_body">
				 
			</div>
			<div class="modal-footer">
				<a href="#" class="btn" data-dismiss="modal">Close</a>
			</div>
		</div>
        
        <div class="clearfix"></div>
		
	<?php $this->load->view('admin/inc/footer');?>
    </div><!--/.fluid-container-->

    
    <!-- Third party script for BrowserPlus runtime (Google Gears included in Gears runtime now) -->
    <script type="text/javascript" src="http://bp.yahooapis.com/2.4.21/browserplus-min.js"></script>
    
    <!-- Load plupload and all it's runtimes and finally the jQuery queue widget -->
    <script type="text/javascript" src="<?php echo base_url('/')?>plupload/js/plupload.full.js"></script>
    <script type="text/javascript" src="<?php echo base_url('/')?>plupload/js/jquery.plupload.queue/jquery.plupload.queue.js"></script>
    
    <script type="text/javascript" src="<?php echo base_url('/')?>admin_src/js/bootstrap-datepicker.js"></script>
    

	<script type="text/javascript">
	$(document).ready(function(){
		/* ---------- Text Editor ---------- */
		$('#redactor_content').redactor({ 	
					imageUpload: '<?php echo site_url('/')?>my_images/redactor_add_image',
					buttons: ['html', '|', 'formatting', '|', 'bold', 'italic', 'deleted', '|', 
					'unorderedlist', 'orderedlist', 'outdent', 'indent', '|','image',
					'video', 'table','|',
					 'alignment', '|', 'horizontalrule']
		});
		
		$('#dob').datepicker()	
	
	});
	
	$('#butt').bind('click' ,function(e) {
	
		
		e.preventDefault();
		//Validate
		if($('#name').val().length == 0){
				
				$('#name').popover({  delay: { show: 100, hide: 3000 },placement:"top",html: true,trigger: "manual", title:"Title Required", content:"Please supply us with a member title"});
				$('#name').popover('show');
				$('#name').focus();
		
		//}else if($('#redactor_content').val() == 0){
//	
//				$('#redactor_content_msg').popover({  delay: { show: 100, hide: 3000 },placement:"top",html: true,trigger: "manual", title:"Page Body", content:"Please supply us with some page content"});
//				$('#redactor_content_msg').popover('show');
//				$('#redactor_content_msg').focus();		
					
			
		}else{
	
			submit_form();
			
		}
	});
	
	$('div.btn-group button').live('click', function(){
		
		$('#status').attr('value', $(this).html());
	});
	
	function submit_form(){
			
			var frm = $('#member-update');
			//frm.submit();
			$('#butt').html('<img src="<?php echo base_url('/').'admin_src/img/loading_white.gif';?>" /> Working...');
			$.ajax({
				type: 'post',
				data: frm.serialize(),
				url: '<?php echo site_url('/').'admin/update_member_do';?>' ,
				success: function (data) {
					 $('#autosave').val('true');
					 $('#result_msg').html(data);
					 $('#butt').html('Update Member');
					
				}
			});	
	
	}
	
	
	window.onbeforeunload = function() {
   		 
		 if($('#autosave').val() == 'false'){
			return 'The member has not been saved.'; 
			
		 }
		 
	};
	$('input').change(function() {

	  $('#autosave').val('false');
	});
	$('.redactor_box').live('click', function() {

	  $('#autosave').val('false');
	});
	
	
	$(function() {
		function log() {
			var str = "";
	
			plupload.each(arguments, function(arg) {
				var row = "";
	
				if (typeof(arg) != "string") {
					plupload.each(arg, function(value, key) {
						// Convert items in File objects to human readable form
						if (arg instanceof plupload.File) {
							// Convert status to human readable
							switch (value) {
								case plupload.QUEUED:
									value = 'QUEUED';
									break;
	
								case plupload.UPLOADING:
									value = 'UPLOADING';
									break;
	
								case plupload.FAILED:
									value = 'FAILED';
									break;
	
								case plupload.DONE:
									value = 'DONE';
									break;
							}
						}
	
						if (typeof(value) != "function") {
							row += (row ? ', ' : '') +  value;
							$('#doc_msg').append(value)
						}
					});
	
					str += row + " ";
				} else { 
					str += arg + " ";
				}
			});
	
			//$('#doc_msg').append(str);
		}
	
		$("#uploader").pluploadQueue({
			// General settings
			runtimes : 'html5,gears,flash,silverlight,browserplus,html4',
			url : '<?php echo site_url('/')?>admin/add_member_docs/',
			max_file_size : '10mb',
			chunk_size : '1mb',
			unique_names : true,
			multipart_params: {member_id : '<?php echo $member_id;?>'},
	
			// Resize images on clientside if we can
			resize : {width : 320, height : 240, quality : 90},
	
			// Specify what files to browse for
			filters : [
				{title : "Documents", extensions : "pdf,doc,docx,DOC,DOCX,PDF,xls,xlsx,XLS"}
			],
	
			// Flash settings
			flash_swf_url : '<?php echo base_url('/')?>plupload/js/plupload.flash.swf',
	
			// Silverlight settings
			silverlight_xap_url : '<?php echo base_url('/')?>plupload/js/plupload.silverlight.xap',
	
			// Post init events, bound after the internal events
			init : {


				FileUploaded: function(up, file, info) {
					// Called when a file has finished uploading
					//log( info);
					load_documents();
				},
	
				Error: function(up, args) {
					// Called when a error has occured
					//log('[error] ', args);
				}
			}
		});
	});
	
	
	function delete_document(id){
			  
			$('#modal-doc-delete').bind('show', function() {
				//var id = $(this).data('id'),
					removeBtn = $(this).find('.btn-primary');
						
					removeBtn.unbind('click').click(function(e) { 
						e.preventDefault();	
						$.ajax({
						  url: "<?php echo site_url('/');?>admin/delete_document/"+id+"/",
						  success: function(data) {
							
							$('footer').html(data);
							$('#modal-doc-delete').modal('hide');
							window.location = "<?php echo current_url('/');?>";
						  }
						});
						
					});
			}).modal({ backdrop: true });
	}
	
	function update_document(id){
			  
			$('#modal-doc-update').bind('show', function() {
					
					  $.ajax({
						cache: false, 
						method: "post",
						url: "<?php echo site_url('/');?>admin/update_document/"+id+"/<?php echo rand(0,9999);?>",
						success: function(data) {
						  $('#doc_update_body').empty();
						  $('#doc_update_body').html(data);
						  //$('#modal-doc-update').modal('hide');
						  
						}
					});
					
			}).modal({ backdrop: true });
	}
	
	
	
	function load_documents(){
	  
		  $.ajax({
			cache: false,
			method: "post",  
			url: "<?php echo site_url('/');?>admin/load_documents/<?php echo $member_id;?>/<?php echo rand(0,9999);?>",
			success: function(data) {
			  $('#member_docs').empty();
			  $('#member_docs').html(data);

			}
		  });			
			
	}
	</script>
</body>
</html>