Example #1
0
    function AddTask($runat, $module = '', $profile_page = '', $profile_id = '', $obj = 'task', $btn_name = '', $order_id = '', $pro_id = '')
    {
        if ($module == '') {
            $module = 'TBL_CONTACT';
        }
        if ($profile_page == '') {
            $profile_page = 'contact_profile.php';
        }
        if ($profile_id == '') {
            $profile_id = 'contact_id';
        }
        switch ($runat) {
            case 'local':
                //display form
                if (count($_POST) > 0) {
                    extract($_POST);
                    $this->due_date = $due_date;
                    $this->description = $description;
                    $this->check = $check;
                    $this->cat_id = $cat_id;
                    $this->module = $module;
                    //$this->module_id=$module_id;
                    $this->contact_id = $this->module_id;
                    $this->title = $title;
                    $this->comment = $comment;
                    $this->order_id = $order_id;
                    $this->pro = $pro_id;
                    $this->assigned_to = $assigned_to;
                }
                //create client side validation
                $FormName = 'frm_task';
                $ControlNames = array("title" => array('title', "''", "Please enter title", "spannew_task"));
                $ValidationFunctionName = 'ValidateTask';
                $JsCodeForFormValidation = $this->Validity->ShowJSFormValidationCode($FormName, $ControlNames, $ValidationFunctionName, $SameFields, $ErrorMsgForSameFields);
                echo $JsCodeForFormValidation;
                ?>
					<form method="post" action="" enctype="multipart/form-data" name="<?php 
                echo $FormName;
                ?>
" id="<?php 
                echo $FormName;
                ?>
" autocomplete="off">
					<input type="hidden" value="" name="caldate" id="caldate" />
					<input type="hidden" value="" name="calhours"  id="calhours"/>
					<input type="hidden" value="" name="calminutes" id="calminutes" />
					
					<table class="table" width="100%" ><tr>
					<td colspan="2" class="textb">Add New Task&nbsp;<span id="spannew_task"></span></td>
					</tr>
					<tr><td colspan="2">
					<input type="text" name="title" id="title" value=""/>
					</td></tr>
					<tr>
					<td colspan="2">
					Comment:<br/>
					<textarea id="comment" name="comment"  style="height:100px ;width:290px"  value=""></textarea>
					</td>
					</tr>
					<tr><th>
					When's it due :</th>
					</tr>
					<tr>
					<td class="no_padding">
					<div id="calendar-container<?php 
                echo $order_id . $pro_id;
                ?>
"></div>
					<span id="spandue_date<?php 
                echo $order_id . $pro_id;
                ?>
"></span>
					</td>
					</tr>
					<tr align="center" style="display:none;" id="cal">
					<td colspan="2">
					</td></tr>
					<script type="text/javascript">//<![CDATA[
						function showCalender(){	
							Calendar.setup({
							cont          : "calendar-container<?php 
                echo $order_id . $pro_id;
                ?>
",
							weekNumbers   : true,
							selection     : Calendar.dateToInt(new Date()),
							showTime      : 12,
							onSelect      : function(cal) {
							document.getElementById('<?php 
                echo $FormName;
                ?>
').caldate.value=this.selection.print("%d-%m-%Y");
							document.getElementById('<?php 
                echo $FormName;
                ?>
').calhours.value=cal.getHours();
							document.getElementById('<?php 
                echo $FormName;
                ?>
').calminutes.value=cal.getMinutes();
							},
							onTimeChange  : function(cal) {
							
							document.getElementById('<?php 
                echo $FormName;
                ?>
').caldate.value=this.selection.print("%d-%m-%Y");
							document.getElementById('<?php 
                echo $FormName;
                ?>
').calhours.value=cal.getHours();
							document.getElementById('<?php 
                echo $FormName;
                ?>
').calminutes.value=cal.getMinutes();
							}
							});
						}
						showCalender();
					//]]></script>
					
					<input type="hidden" name="module" id="module" value="TBL_CONTACT"/>
					<input type="hidden" id="module_id" name="module_id" value="<?php 
                echo $this->module_id;
                ?>
"> 
				    <tr><th>
					Who's responsible :</th>
					</tr>
					<tr>
					<td>			 
					<?php 
                $users = new User();
                echo $users->GetAllUserInList('assigned_to', $this->user_id, '', 'yes', $this->user_id);
                ?>
    			 	
				    <span id="spanmodule_id"></span>
					<?php 
                $sql_group = "select * from " . TBL_USERGROUP . " order by group_name";
                $result_group = $this->db->query($sql_group, __FILE__, __LINE__);
                ?>
					<select name="user_group" id="user_group">
						<option value="">---select group---</option>
						<?php 
                while ($row_group = $this->db->fetch_array($result_group)) {
                    ?>
							<option value="<?php 
                    echo $row_group['group_id'];
                    ?>
"><?php 
                    echo $row_group['group_name'];
                    ?>
</option>
						<?php 
                }
                ?>
					</select>
					</td>
				  	</tr>
					<tr>
					<td colspan="2">
					<input name="check" type="checkbox" checked="checked" id="check" value="yes" style="width:auto"/>
					&nbsp;&nbsp;Let everyone to see this task
					<span id="spanchek"></span>
					</td></tr>
					<tr><th>
					Category : </th></tr>
					<tr>
					<td><span>
					<select name="cat_id" id="cat_id" onChange="if(this.value=='NewCat'){ 
																	category = prompt('Enter name of category','');
																	if(category!=null){
																	if(category.length>0)
																	{
																		<?php 
                echo $obj;
                ?>
.Add_Fly_Cat('server',category,'#0000FF',
																		{	onUpdate: function(response,root){  
																			if(response==1)
																			<?php 
                echo $obj;
                ?>
.GetTaskCategoryJson({content_type:'json', target:'cat_id', preloader:'prl'});
																			else {
																			alert('Sorry !! category with name '+category+' already exists');
																			document.getElementById('cat_id').options[0].selected = true;
																			document.getElementById('cat_id').selectedIndex=0;
																			return true;
																				}
																			}});
																	}
																	else{
																	this.options[0].selected = true;
																	this.selectedIndex=0;
																	return true;
																	} }
																	else 
																	{
																	this.options[0].selected = true;
																	this.selectedIndex=0;
																	return true;
																	}}">
					<option value="">select category</option>
					<?php 
                $sql = "select * from " . TASKS_CATEGORY . " order by name";
                $result = $this->db->query($sql, __FILE__, __LINE__);
                while ($row = $this->db->fetch_array($result)) {
                    ?>
                    <option value="<?php 
                    echo $row['cat_id'];
                    ?>
"><?php 
                    echo $row['name'];
                    ?>
</option>
					 <?php 
                }
                ?>
					 <option value="NewCat" >new category</option>
					</select></span>&nbsp;<span><a href="categoryManagement.php">edit categories</a></span>
					<span id="spancat_id"></span>
					</td></tr>
					<tr>
					<td colspan="2">
					Select the Document to upload: <input type="file" name="myfile"> 
					</td>
					</tr>
					<tr>
					<td colspan="2">
					<input type="hidden" id="hide_pro123" name="hide_pro123" value="<?php 
                echo $this->pro;
                ?>
"/>
					<input type="submit" name="<?php 
                if ($btn_name == 'ORDER') {
                    echo "Save_ORDER";
                } else {
                    if ($btn_name == 'WORK_ORDER') {
                        echo "Save_WORK_ORDER";
                    } else {
                        if ($btn_name == 'REWORK_ORDER') {
                            echo 'save_REWORK_ORDER';
                        } else {
                            echo "Save";
                        }
                    }
                }
                ?>
" value="Add this Task" id="Save" style="width:auto"  onClick="slimcrm.test_serialize = $('#<?php 
                echo $FormName;
                ?>
').serialize();$.post('task.php', $('#<?php 
                echo $FormName;
                ?>
').serialize() , function( data, textStatus,jqXHR){ $('#task_form').hide();<?php 
                echo $this->refresh_js;
                ?>
} ); return false;" />
					</td></tr></table>
					</form>
					<?php 
                break;
            case 'server':
                //Reading Post Date
                $this->module = $module;
                $this->profile_page = $profile_page;
                $this->profile_id = $profile_id;
                extract($_POST);
                $this->due_date = $due_date;
                $this->description = $description;
                $this->check = $check;
                $this->cat_id = $cat_id;
                $this->module_id = $module_id;
                $this->title = $title;
                $this->comment = $comment;
                $this->assigned_to = $assigned_to;
                $this->order_id = $order_id;
                $this->product_id = $pro_id;
                $this->document_name = $_FILES['myfile']['name'];
                $this->document_size = $_FILES['myfile']['size'];
                $this->destination_path = "doc/";
                $this->tdocname = $_FILES['myfile']['name'];
                if ($this->document_size > 0) {
                    ///ne upload
                    $doc_name = $this->getRandomName($this->document_name);
                    $target_path = $this->destination_path . basename($doc_name);
                    move_uploaded_file($_FILES['myfile']['tmp_name'], $target_path);
                    $this->tservername = $this->getRandomName($this->document_name);
                }
                if ($this->due_date == '') {
                    $date = array();
                    $date = explode('-', $caldate);
                    if (substr($date[0], 0, 1) == '0') {
                        $date[0] = substr($date[0], 1, 1);
                    }
                    if (substr($date[1], 0, 1) == '0') {
                        $date[1] = substr($date[1], 1, 1);
                    }
                    //////////////////////////////////////////////////date///////////////////////////
                    $this->due_date = mktime($calhours, $calminutes, 0, $date[1], $date[0], $date[2]);
                }
                $return = true;
                if ($this->Form->ValidField($title, 'empty', 'Please enter task title') == false) {
                    $return = false;
                }
                if ($return) {
                    $insert_sql_array = array();
                    $insert_sql_array['title'] = $this->title;
                    $insert_sql_array['user_id'] = $this->user_id;
                    $insert_sql_array['comment'] = $this->comment;
                    $insert_sql_array['doc_name'] = $this->tdocname;
                    $insert_sql_array['doc_server_name'] = $doc_name;
                    $insert_sql_array['due_date'] = $this->due_date;
                    $insert_sql_array['description'] = $this->description;
                    if ($this->check != '') {
                        $insert_sql_array['is_global'] = $this->check;
                    }
                    $insert_sql_array['cat_id'] = $this->cat_id;
                    $this->db->insert(TASKS, $insert_sql_array);
                    $this->task_id = $this->db->last_insert_id();
                    $insert_sql_array = array();
                    $insert_sql_array['task_id'] = $this->task_id;
                    $insert_sql_array['module'] = $this->module;
                    $insert_sql_array['module_id'] = $this->module_id;
                    $insert_sql_array['profile_page'] = $this->profile_page;
                    $insert_sql_array['profile_id'] = $this->profile_id;
                    $insert_sql_array['order_id'] = $this->order_id;
                    $insert_sql_array['product_id'] = $this->product_id;
                    $this->db->insert(ASSIGN_TASK, $insert_sql_array);
                    //uploadfile
                    if ($this->assigned_to) {
                        $this->module = 'TBL_USER';
                        $this->module_id = $this->assigned_to;
                        $insert_sql_array = array();
                        $insert_sql_array['task_id'] = $this->task_id;
                        $insert_sql_array['module'] = $this->module;
                        $insert_sql_array['module_id'] = $this->module_id;
                        $this->db->insert(TASK_RELATION, $insert_sql_array);
                    }
                    if ($user_group) {
                        $this->module = 'TBL_USERGROUP';
                        $this->module_id = $user_group;
                        $insert_sql_array = array();
                        $insert_sql_array['task_id'] = $this->task_id;
                        $insert_sql_array['module'] = $this->module;
                        $insert_sql_array['module_id'] = $this->module_id;
                        $this->db->insert(TASK_RELATION, $insert_sql_array);
                    }
                    $_SESSION['msg'] = 'Task has been successfully created';
                    ?>
					<script type="text/javascript">
						window.location="<?php 
                    echo $_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING'];
                    ?>
";
					</script>
					<?php 
                    exit;
                } else {
                    echo $this->Form->ErrtxtPrefix . $this->Form->ErrorString . $this->Form->ErrtxtSufix;
                    $this->AddTask('local');
                }
                break;
            default:
                echo 'Wrong Paramemter passed';
        }
    }