setBoxByTabs($key,$metabox_obj['positioning']); } else if(isset($metabox_obj['fields'])){ $this->setBoxByFields($key,$metabox_obj['fields']); } } public function setBoxByTabs($key,$positioning) { global $post; if(count($positioning['main'])>0){ echo '
'; $c=0; $ctotal=count($positioning['main']); foreach($positioning['main'] as $fieldset){ $c++; $class='apm_li_inline'; if($c==$ctotal){ $class='apm_li_inline_last'; } echo ''; } echo '
'; } if(isset($positioning['tabs']) and count($positioning['tabs'])>0){ echo '
'; if(count($positioning['tabs'])>1){ echo ' '; } echo '
'; foreach($positioning['tabs'] as $subkey => $tab){ echo '
    '; $c=0; $ctotal=count($positioning['main']); foreach($tab['items'] as $fieldset){ $c++; $class='apm_li_inline'; if($c==$ctotal){ $class='apm_li_inline_last'; } echo '
      '; $pos='inline'; if(count($fieldset )==1){ $pos='regular'; } $total_width=0; foreach($fieldset as $field){ $width=10; if(isset($this->default_fields[$field])){ $f=$this->default_fields[$field]; isset($f['width']) ? $width=intval($f['width']): $width=10; } $total_width+=$width; } foreach($fieldset as $field){ $this->setField($field,'
    • ','
    • ',$pos,$total_width); } echo '
    '; } echo '
'; } echo '
'; } } public function setBoxByFields($key,$fields) { global $post; foreach($fields as $field){ $this->setField($field); } } ///////////////// public function setField($field,$before_field='

',$after_field='

',$global_label_type=false,$total_width=10) { global $post,$meta_marker; if(isset($this->default_fields[$field])){ $f=$this->default_fields[$field]; isset($f['field_type']) ? $field_type=$f['field_type'] : $field_type='textfield'; isset($f['default']) ? $default=$f['default'] : $default=''; isset($f['child_second_parent']) ? $child_second_parent=$f['child_second_parent'] : $child_second_parent=''; isset($f['child_key']) ? $child_key=$f['child_key'] : $child_key=''; isset($f['label_position']) ? $label_position=$f['label_position'] : $label_position='left'; isset($f['description']) ? $description=$f['description'] : $description=''; isset($f['info']) ? $info=$f['info'] : $info=''; isset($f['help']) ? $help=$f['help'] : $help=''; isset($f['hide_label']) ? $hide_label=$f['hide_label'] : $hide_label=''; isset($f['image_resize']) ? $image_resize=$f['image_resize'] : $image_resize=false; isset($f['label_width']) ? $label_width=$f['label_width'] : $label_width=150; isset($f['width']) ? $width=' width:'.(intval($f['width'])*10 ).'%; ': $width=''; isset($f['width']) ? $widthli=intval($f['width']) :$widthli=10; isset($f['label_width_perc']) ? $label_width_perc=intval($f['label_width_perc']) :$label_width_perc=0; isset($f['options']) ? $options=$f['options']: $options=array(); isset($f['html']) ? $html=$f['html']: $html=""; isset($f['use_none']) ? $use_none=$f['use_none']: $use_none=""; isset($f['maxlength']) ? $maxlength=$f['maxlength']: $maxlength=""; isset($f['label_type']) ? $label_type=$f['label_type']: $label_type='regular'; if($global_label_type!==false){ $label_type=$global_label_type; } isset($f['allow_multi_files']) ? $allow_multi_files=$f['allow_multi_files']: $allow_multi_files=false; isset($f['field_config']) ? $field_config=$f['field_config']: $field_config=''; isset($f['required']) ? $required=$f['required']: $required=false; isset($f['restrict_format']) ? $restrict_format=$f['restrict_format']: $restrict_format=false; $field_value = get_post_meta($post->ID, $field.$meta_marker, true); empty($field_value) ? $value=$default : $value=$field_value ; $post_type=get_post_type( $post ); ///DEFINE PARENT ID, in case we need it... Only if we defined in module config, the follow: /*'define_parent'=>array( 'parent_post_type'=>'fgl_companies', 'parent_post_field'=>'fgl_company_parent' ), * * */ $parent_id=0; foreach( $this->applications as $key => $application ){ if(isset($application['modules'][$post_type])){ $parent_post_type=$application['modules'][$post_type]['define_parent']['parent_post_type']; $parent_post_field=$application['modules'][$post_type]['define_parent']['parent_post_field']; if(isset($_GET['post'])){//=is edit $parent_id = get_post_meta($post->ID, $parent_post_field.$meta_marker, true); } else if (isset($_GET['parent_id'])){ $parent_id =$_GET['parent_id']; } }; } $args=array( 'value' => $value, 'hide_label' => $hide_label, 'required' => $required, 'restrict_format' => $restrict_format, 'parent_id' => $parent_id, 'label_width' => $label_width, 'label_width_perc' => $label_width_perc, 'image_resize' => $image_resize, 'allow_multi_files' => $allow_multi_files, 'html' => $html, 'width' => $width, 'widthli' => $widthli, 'total_width' => $total_width, 'child_key' => $child_key, 'info' => $info, 'description' => $description, 'help' => $help, 'child_second_parent' => $child_second_parent, 'use_none' => $use_none, 'options' => $options, 'maxlength' => $maxlength, 'field_config' => $field_config, 'label_position' => $label_position, 'field' => $field, 'before_field' => $before_field, 'after_field' => $after_field, 'label' => $f['label'] , 'label_type' => $label_type ); switch($field_type){ case 'add_child': $this->setAddChild($args); break; case 'textfield': $this->setTextField($args); break; case 'hiddenfield': $this->setHiddenField($args); break; case 'autocomplete': $this->setAutocomplete($args); break; case 'convert_button': $this->setConvertButton($args); break; case 'action_button': $this->setActionButton($args); break; case 'auto_set_title': $this->setAutoSetTitle($args); break; case 'created_by': $this->setCreatedBy($args); break; case 'created_date': $this->setCreatedDate($args); break; case 'modified_date': $this->setModifiedDate($args); break; case 'numberfield': $this->setNumberField($args); break; case 'currencyfield': $this->setCurrencyField($args); break; case 'html': $this->setHTML($args); break; case 'textarea': $this->setTextArea($args); break; case 'select': $this->setSelect($args); break; case 'checkbox': $this->setCheckbox($args); break; case 'uploadfield': $this->setUploadField($args); break; case 'richtexteditor': $this->setRTEditor($args); break; case 'childgrid': $this->setChildGrid($args); break; case 'radio': $this->setRadio($args); break; case 'userslist': $this->setUsersList($args); break; case 'datefield': $this->setDatePicker($args); break; case 'autoincrementfield': $this->setAutoIncrementField($args); break; case 'comments': $this->setComments($args); break; case 'assignee': $this->setAssignments($args); break; case 'notifications_rules': $this->setNotificationsRules($args); break; case 'notifications': $this->setNotifications($args); break; } } } public function getDescription($config,$default_description="",$default_help="",$addBr=false) { if($config['description']!==''){ if($addBr){ echo'
'; } echo ''.$config['description'].''; } else if ($default_description!==''){ if($addBr){ echo'
'; } echo ''.$default_description.''; } if($config['help']!==''){ $help_image = WP_PLUGIN_URL.'/'.WP_PLUGIN_FOLDER.'/img/bugsqa_16.png'; echo ''.$config['help'].''; } } public function getMaxLength($config) { $maxlength =''; if($config['maxlength']!==''){ $maxlength =' maxlength="'.$config['maxlength'].'" '; } return $maxlength; } public function setAssignments($config) { global $meta_marker,$apm_settings; $post_id=$_GET['post']; $assign_rule_apply_child='0'; if($config['parent_id']!==0){ $assign_rule_apply_child= get_post_meta($config['parent_id'], 'assign_rule_apply_child'.$meta_marker, true); } $width=intval(100/$config['total_width']*$config['widthli'])-2; echo '
  • '; echo $this->setLabel($config); //echo $config['info'].": "; if($config['label_width_perc']>0){ echo '
    '; } wp_dropdown_users( array( 'name' => $config['field'].$meta_marker, 'selected' => $config['value'], 'show' => 'display_name' ) ); $this->getDescription($config); if($config['label_width_perc']>0){ echo '
    '; } //echo " "; echo '
  • '; } public function getNotifRuleValue($fieldvalue,$selectvalue,$force_if_new) { $select=''; if($force_if_new and !isset($_GET['action'])){ $select=' selected="selected" '; } else { foreach($fieldvalue as $key=>$value){ if($value==$selectvalue){ $select=' selected="selected" '; } } } return $select; } public function setNotificationsRules($config) { global $meta_marker,$apm_settings; $post_id=$_GET['post']; //Check if we need to aplly the same setting than the parent object... 1 if yes. $assign_rule_apply_child='0'; if($config['parent_id']!==0){ $assign_rule_apply_child= get_post_meta($config['parent_id'], 'assign_rule_apply_child'.$meta_marker, true); } echo $config['before_field'].$this->setLabel($config)."
    "; echo "
    Notify also the following users for each post update:
    "; //echo var_dump($config['value']); if(isset( $config['field_config']['notify_assignee'] ) and $config['field_config']['notify_assignee'] == true ){ echo 'Assignee:'; echo ' - "; //
    ';//'. checked(!empty($config['value']), true, false) . ' } if(isset( $config['field_config']['notify_full_team'] ) and $config['field_config']['notify_full_team'] == true ){ echo 'Whole team:'; echo ' - "; //
    ';//'. checked(!empty($config['value']), true, false) . ' } if(isset( $config['field_config']['notify_udpater'] ) and $config['field_config']['notify_udpater'] == true ){ echo 'Updater:'; echo '
    "; //
    ';//'. checked(!empty($config['value']), true, false) . ' } echo "
    Notify also the following users for each comment:
    "; if(isset( $config['field_config']['comment_assignee'] ) and $config['field_config']['comment_assignee'] == true ){ echo 'Assignee:'; echo ' -"; //
    ';//'. checked(!empty($config['value']), true, false) . ' } if(isset( $config['field_config']['comment_notify_full_team'] ) and $config['field_config']['comment_notify_full_team'] == true ){ echo 'Whole team:'; echo ' - "; //
    ';//'. checked(!empty($config['value']), true, false) . ' } if(isset( $config['field_config']['comment_notify_selected'] ) and $config['field_config']['comment_notify_selected'] == true ){ echo 'All the users selected for Post notification'; echo '"; //
    ';//'. checked(!empty($config['value']), true, false) . ' } $this->getDescription($config); echo $config['after_field']; } public function setNotifications($config) { global $meta_marker,$apm_settings; $post_id=$_GET['post']; $assign_rule_apply_child='0'; if($config['parent_id']!==0){ $assign_rule_apply_child= get_post_meta($config['parent_id'], 'assign_rule_apply_child'.$meta_marker, true); } echo $config['before_field'].$this->setLabel($config)."
    "; /*if(isset( $config['field_config']['notify_assignee'] ) and $config['field_config']['notify_assignee'] == true ){ }*/ $usersids=explode(',',$config['value']); $userslist=get_users( array( 'include' =>$usersids ) ); echo '
    '; foreach($userslist as $user){ echo "".$user->user_login. "
    "; } echo '
    '; $this->getDescription($config); echo "
    Add more: "; wp_dropdown_users( array( 'name' => $config['field']."show_users", 'selected' => $config['value'], 'show' => 'display_name', 'exclude' => $config['value'] ) ); echo " "; echo ''; echo $config['after_field']; } public function setComments($config) { global $meta_marker,$apm_settings; if (isset($_GET['post']) and !empty($_GET['post'])){ $post_id=$_GET['post']; } else { $post_id='false'; } echo $config['before_field'].$this->setLabel($config)."
    "; if(isset($_GET['action'])){ $comments=get_comments( 'post_id='. $post_id); echo "Nb of comment(s): ".count($comments).'
    '; } else { echo 'No comments yet, this is a new post...
    '; } $cls=''; if(count($comments)==0){ //$cls=" apm_hidden"; } require_once APPLICATION_MAKER_VIEWS_PATH . 'apm-comments-tpl.php'; echo "
    ".$view."
    "; echo "
    Submitting, please wait...
    "; echo "
    Add comment:
    "; echo ' '; //fgl_submitComment(\''.$config['field'].$meta_marker.'_comment\',\''.$config['field'].'\',\''.$post_id.'\');" echo ""; if(isset($_GET['action'])){ echo ''; } else { echo "This comment will be submitted when you'll save the post"; } //ADD a lang selection if(isset( $config['field_config']['use_lang'] ) and $config['field_config']['use_lang'] == true ){ echo '
    "; } echo "
    "; echo "
    "; $strview=''; if(isset($_GET['action'])){ foreach($comments as $comment) : //get_avatar( $comment->comment_author_email, 48 ); $nview=str_replace('[[username]]', $comment->comment_author, $view); // $nview=str_replace('[[comment_author_email]]', $comment->comment_author_email, $nview); $da=$comment->comment_date; $day=substr($da,0,10); $time=substr($da,12,8); $curday=date('Y-M-d'); if($curday==$day){ $day='Today'; } $nview=str_replace('[[date]]', $day, $nview); $GLOBALS['comment'] = $comment; $lang_str=''; if(!empty($comment->comment_author_email)){ $lang_str=' - Language: '.$comment->comment_author_email; } $nview=str_replace('[[lang_zone]]', $lang_str, $nview); $nview=str_replace('[[id]]', get_comment_id(), $nview); $nview=str_replace('[[time]]', $time, $nview);// $nview=str_replace('[[fieldname]]', '"'.$config['field'].'"', $nview);// $nview=str_replace('[[comment]]', get_comment_text(), $nview); $strview= $nview.$strview; endforeach; echo $strview; } echo "
    "; $this->getDescription($config); echo $config['after_field']; } public function setAutocomplete($config) { global $post,$meta_marker; $select_post_type=false; $display_value=''; if(isset($config['field_config']['post_type']) ){ $select_post_type=$config['field_config']['post_type']; } if(isset($_GET['apm_do']) ){ if($_GET['apm_do']=='set_select' and $_GET['parent_post_type']==$select_post_type){ $config['value']=$_GET['parent_id']; } if($_GET['apm_do']=='set_select' and $_GET['second_parent_post_type']==$select_post_type){ $config['value']=$_GET['second_parent_id']; } } if($config['value']!==''){ $p=get_post($config['value']); if( count( $p ) > 0 ){ $display_value=$p->post_title; } } echo "
    ".$this->setLabel($config); if($config['label_width_perc']>0){ echo '

    '; } else { echo ''; } //'description' => 'AutoSuggest field: Start type the 2 first characters to get the Suggestions', $this->getDescription($config,'AutoSuggest field: Start type the 2 first characters to get the Suggestions','',false); if($config['value']!==''){ $new_window_image = WP_PLUGIN_URL.'/'.WP_PLUGIN_FOLDER.'/img/new_window_icon.gif'; if(isset($_GET['action']) and $_GET['action']=='edit' ){// $jumpBtn= '
    '.sprintf( '%s', esc_url( add_query_arg( array( 'action' => 'edit', 'post' => $config['value']), 'post.php' ) ), "" ); $jumpBtn.=" ".sprintf( '%s', esc_url( add_query_arg( array( 'action' => 'edit', 'post' => $config['value']), 'post.php' ) ), _('Open the selected parent article') ); echo $jumpBtn; } } echo "
    "; } public function setAutoSetTitle($config) { global $meta_marker; $schema=''; if(isset($config['field_config']['schema']) ){ $schema=$config['field_config']['schema']; $itemarray1=explode('{',$schema); $str=$schema; $fields_arr=array(); foreach($itemarray1 as $item){ $itemarray2=explode('}',$item); $s=$itemarray2[0]; if($s!==''){ array_push($fields_arr,array( 'field'=>$s, 'field_type'=>$this->default_fields[$s]['field_type'] )); /*if(!isset($this->default_fields[$s]['field_type']) or ($this->default_fields[$s]['field_type'])=='numberfield' or ($this->default_fields[$s]['field_type'])=='textfield' or ($this->default_fields[$s]['field_type'])=='autoincrementfield' or ($this->default_fields[$s]['field_type'])=='currencyfield' or ($this->default_fields[$s]['field_type'])=='datefield'){ $post_id=$_GET['post']; $val=get_post_meta($post_id, $child_second_parent[0].'_value', true); }*/ } } $final_array=array( 'fields'=>$fields_arr, 'schema'=>$schema ); echo ''; if(isset($config['field_config']['hide_btn']) and $config['field_config']['hide_btn']==true){ } else { echo ''; } if(isset($config['field_config']['hide_title']) and $config['field_config']['hide_title']==true){ echo ''; } if(isset($config['field_config']['auto_on_save']) and $config['field_config']['auto_on_save']==true){ echo ''; } } } public function setAutoIncrementField($config) { global $post,$meta_marker; $width=intval(100/$config['total_width']*$config['widthli'])-2; echo '
  • '.$this->setLabel($config); if(isset($_GET['action']) and $_GET['action']=='edit'){ } else { $post_type=get_post_type( $post ); $val=$this->get_highest_value($post_type,$config['field']); $val=intval($val)+1; if($val<10){ $config['value']='00'.$val; } else if($val<100){ $config['value']='0'.$val; } else { $config['value']=$val; } } if($config['label_width_perc']>0){ echo '
    '; echo ''; echo '
    '; } else { echo ''; } $this->getDescription($config); echo '
  • '; } public function setConvertButton($config) { global $post,$meta_marker; //var_dump($config); $post_type=get_post_type( $post ); $appname=''; foreach( $this->applications as $key => $application ){ if(isset($application['modules'][$post_type])){ $appname=$key; } } $width=intval(100/$config['total_width']*$config['widthli'])-2; $post_id=$_GET['post']; echo '
  • '; echo ''; $this->getDescription($config); echo '
  • '; } public function setActionButton($config) { global $post,$meta_marker; //var_dump($config); $post_type=get_post_type( $post ); $appname=''; foreach( $this->applications as $key => $application ){ if(isset($application['modules'][$post_type])){ $appname=$key; } } $width=intval(100/$config['total_width']*$config['widthli'])-2; $post_id=$_GET['post']; $test=true; if(isset($config['field_config']['limit_to_edit']) and $config['field_config']['limit_to_edit']==true and $post_id==''){ $test=false; } if(isset($config['field_config']['hide_on_fields_values']) ){ foreach($config['field_config']['hide_on_fields_values'] as $key => $field_restrict){ $v=get_post_meta($post_id, $field_restrict[0].$meta_marker, true); $fva=explode(',',$field_restrict[1]); foreach($fva as $fv){ if(intval($v)==intval($fv)){ $test=false; } } } } if($test) { echo '
  • '; echo ''; $this->getDescription($config); echo '
  • '; } } public function setCreatedBy($config) { global $meta_marker; $width=intval(100/$config['total_width']*$config['widthli'])-2; echo '
  • '; echo $this->setLabel($config); $post_id=$_GET['post']; $post=get_post($post_id); $user=get_users(array( 'include' =>$post->post_author ) ); echo $user[0]->display_name; $this->getDescription($config); echo '
  • '; } public function setCreatedDate($config) { global $meta_marker; $width=intval(100/$config['total_width']*$config['widthli'])-2; echo '
  • '; echo $this->setLabel($config); $post_id=$_GET['post']; $post=get_post($post_id); echo $post->post_date; $this->getDescription($config); echo '
  • '; } public function setModifiedDate($config) { global $meta_marker; $width=intval(100/$config['total_width']*$config['widthli'])-2; echo '
  • '; echo $this->setLabel($config); $post_id=$_GET['post']; $post=get_post($post_id); echo $post->post_modified; $this->getDescription($config); echo '
  • '; } //setHiddenField public function setHiddenField($config) { global $meta_marker; echo ''; } public function setTextField($config) { global $meta_marker; $width=intval(100/$config['total_width']*$config['widthli'])-2; echo '
  • '; echo $this->setLabel($config); $w=100; if($config['help']!==''){ $w=90; } $req=''; if($config['required']){ $req=" class='apm_is_required' "; } if($config['restrict_format']!==false){ switch($config['restrict_format']){ case 'email': $req=" class='apm_is_email' "; break; case 'numbers': $req=" class='apm_is_numbers' "; break; case 'phone': $req=" class='apm_is_phone' "; break; } } if($config['label_width_perc']>0){ echo '
    '; $this->getDescription($config); echo '
    '; } else { echo ''; $this->getDescription($config); } echo '
  • '; } public function setUsersList($config) { global $meta_marker; $width=intval(100/$config['total_width']*$config['widthli'])-2; echo '
  • '; echo $this->setLabel($config); if($config['label_width_perc']>0){ echo '
    '; wp_dropdown_users( array( 'name' => $config['field'].$meta_marker, 'selected' => $config['value'], 'show' => 'display_name' ) ); echo '
    '; } else { wp_dropdown_users( array( 'name' => $config['field'].$meta_marker, 'selected' => $config['value'], 'show' => 'display_name' ) ); } $this->getDescription($config); echo '
  • '; } public function setNumberField($config) { global $meta_marker; $width=intval(100/$config['total_width']*$config['widthli'])-2; echo '
  • '.$this->setLabel($config); $maxlength =$this->getMaxLength($config); $req=''; if($config['required']){ $req=" class='apm_is_required' "; } if($config['restrict_format']!==false){ switch($config['restrict_format']){ case 'email': $req=" class='apm_is_email' "; break; case 'numbers': $req=" class='apm_is_numbers' "; break; case 'phone': $req=" class='apm_is_phone' "; break; } } if($config['label_width_perc']>0){ echo '
    '; } else { echo ''; } $this->getDescription($config); echo '
  • '; } public function setCurrencyField($config) { global $meta_marker; $width=intval(100/$config['total_width']*$config['widthli'])-2; echo '
  • '; echo $this->setLabel($config); $maxlength =$this->getMaxLength($config); $req=''; if($config['required']){ $req=" class='apm_is_required' "; } if($config['restrict_format']!==false){ switch($config['restrict_format']){ case 'email': $req=" class='apm_is_email' "; break; case 'numbers': $req=" class='apm_is_numbers' "; break; case 'phone': $req=" class='apm_is_phone' "; break; } } if($config['label_width_perc']>0){ echo '
    '; echo ''; echo '
    '; } else { echo ''; } $this->getDescription($config); echo '
  • '; } public function setDatePicker($config) { $calendar_image = site_url().'/wp-admin/images/date-button.gif'; global $meta_marker; $width=intval(100/$config['total_width']*$config['widthli'])-2; echo '
  • '.$this->setLabel($config); $maxlength =$this->getMaxLength($config); if($config['label_width_perc']>0){ echo '
    '; } else { echo ''; } $this->getDescription($config); echo '
  • '; echo ""; } public function getAddBtn($config) { global $wpdb,$meta_marker,$apm_settings; $select_post_type=$config['field_config']['post_type']; $post_id=$_GET['post']; $meta_key=$config['field_config']['child_key']; $new_window_image = WP_PLUGIN_URL.'/'.WP_PLUGIN_FOLDER.'/img/new_window_icon.gif'; $current_post=get_post($post_id); $type_label=$config['label']; $current_post_type=$current_post->post_type; $current_post=get_post($post_id); $type_label=$config['label']; $current_post_type=$current_post->post_type; if( $config['field_config']['child_second_parent'] !== '' ){ $child_second_parent=$config['field_config']['child_second_parent']; $second_parent_field=$this->default_fields[$child_second_parent[0]]; $second_parent_post_type=$second_parent_field['field_config']['post_type']; $second_parent_id=get_post_meta($post_id, $child_second_parent[0].$meta_marker, true); $add_image = WP_PLUGIN_URL.'/'.WP_PLUGIN_FOLDER.'/img/plus_16.png'; $addBtn= sprintf( '%s', esc_url( add_query_arg( array( 'post_type' => $select_post_type, 'parent_id' => $post_id, 'second_parent_id' => $second_parent_id, 'second_parent_post_type' => $second_parent_post_type, 'parent_title' => $current_post->post_title, 'parent_post_type' => $current_post_type, 'apm_do' => 'set_select'), 'post-new.php' ) ), "" ); $addBtn.=" ".sprintf( '%s', esc_url( add_query_arg( array( 'post_type' => $select_post_type, 'parent_id' => $post_id, 'second_parent_id' => $second_parent_id, 'second_parent_post_type' => $second_parent_post_type,'parent_title' => $current_post->post_title, 'parent_post_type' => $current_post_type, 'apm_do' => 'set_select'), 'post-new.php' ) ), "Add a new ".$type_label."" ); } else { $addBtn= sprintf( '%s', esc_url( add_query_arg( array( 'post_type' => $select_post_type, 'parent_id' => $post_id, 'parent_title' => $current_post->post_title, 'parent_post_type' => $current_post_type, 'apm_do' => 'set_select'), 'post-new.php' ) ), "" ); $addBtn.=" ".sprintf( '%s', esc_url( add_query_arg( array( 'post_type' => $select_post_type, 'parent_id' => $post_id, 'parent_title' => $current_post->post_title, 'parent_post_type' => $current_post_type, 'apm_do' => 'set_select'), 'post-new.php' ) ), "Add a new ".$type_label ); } return $addBtn; } public function setAddChild($config) { global $wpdb,$meta_marker,$apm_settings; if(isset($config['field_config']['post_type']) ){ $select_post_type=$config['field_config']['post_type']; $post_id=$_GET['post']; $meta_key=$config['field_config']['child_key']; $addBtn=$this->getAddBtn($config); $width=intval(100/$config['total_width']*$config['widthli'])-2; echo '
  • '; foreach( $this->applications as $key => $application ){ if(isset($application['modules'][$select_post_type])){ $application=$application['modules'][$select_post_type]; if(isset($application['icon'])){ $icon=" "; echo $icon; } } } //echo var_dump($config); echo $this->setLabel($config); echo " $addBtn"; $this->getDescription($config); echo "
  • "; } } public function setChildGrid($config) { global $wpdb,$meta_marker,$apm_settings; if(isset($config['field_config']['post_type']) ){ $select_post_type=$config['field_config']['post_type']; $post_id=$_GET['post']; $meta_key=$config['field_config']['child_key']; $posts = $this->get_posts_list_with_meta($select_post_type,$post_id,$meta_key); echo '
    '.$config['label'].''; $addBtn=$this->getAddBtn($config) ; echo "$addBtn
    "; $columns=array(); if(isset($config['field_config']['columns'])){ $columns=$config['field_config']['columns']; } echo $this->getTableHeader($columns); $count_records=0; $totals=array(); if(isset($config['field_config']['calculations'])) { foreach($config['field_config']['calculations'] as $key=>$calculation){ $totals [$key]=0; } } foreach($posts as $p){ echo ""; $out = sprintf( '%s', esc_url( add_query_arg( array( 'post' => $p->ID, 'action' => 'edit'), 'post.php' ) ), "" ); $out .= sprintf( ' %s', esc_url( add_query_arg( array( 'post' => $p->ID, 'action' => 'edit'), 'post.php' ) ), esc_html( $p->post_title ) ); //echo var_dump($p); foreach($columns as $column){ $f=$this->default_fields[$column]; switch($column){ case "post_title": echo ''.$out.''; break; case "post_date": $h_time = mysql2date( __( 'Y/m/d' ), $p->post_date ); echo ''.$h_time.''; break; case "post_status": echo ''.$p->post_status.''; break; default: $meta=get_post_meta($p->ID, $column.$meta_marker,true); if($meta!==''){ //userslist if(isset($f['field_type']) ){ switch($f['field_type']){ case "select": if(isset($f['field_config']['use_values']) and $f['field_config']['use_values']==true){ $meta=$f['options'][$meta]; } else { $subpost=get_post($meta); $meta_t=$subpost->post_title; $meta=sprintf( '%s', esc_url( add_query_arg( array( 'action' => 'edit', 'post' => $subpost->ID), 'post.php' ) ), $meta_t ); } break; case "autocomplete": $subpost=get_post($meta); $meta_t=$subpost->post_title; $meta=sprintf( '%s', esc_url( add_query_arg( array( 'action' => 'edit', 'post' => $subpost->ID), 'post.php' ) ), $meta_t ); break; case "userslist": $user=get_users(array( 'include' =>$meta ) ); $meta=$user[0]->display_name; break; case "assignee": $user=get_users(array( 'include' =>$meta ) ); $meta=$user[0]->display_name; break; } //echo var_dump($subpost); } } echo ''.$meta.''; break; } } echo ""; /* $out = sprintf( '%s', esc_url( add_query_arg( array( 'post' => $p->ID, 'action' => 'edit'), 'post.php' ) ), "" ); $out .= sprintf( ' %s', esc_url( add_query_arg( array( 'post' => $p->ID, 'action' => 'edit'), 'post.php' ) ), esc_html( $p->post_title ) ); $h_time = mysql2date( __( 'Y/m/d' ), $p->post_date ); echo " ".$out." ".$p->post_status." ".$h_time." ";//$p->post_title;*/ if(isset($config['field_config']['calculations'])) { foreach($config['field_config']['calculations'] as $key=>$calculation){ if(!isset($calculation['type'])){ $type='sum'; } else { $type=$calculation['type']; } switch($type) { case 'sum': $f=$this->default_fields[$key]; $meta=get_post_meta($p->ID, $key.$meta_marker,true); $totals[$key]+=intval($meta); break; case 'average': $f=$this->default_fields[$key]; $meta=get_post_meta($p->ID, $key.$meta_marker,true); $totals[$key]+=intval($meta); break; } } } } echo $this->getTableFooter($columns); if(isset($config['field_config']['calculations'])) { foreach($config['field_config']['calculations'] as $key=>$calculation){ $total=0; if(!isset($calculation['type'])){ $type='sum'; } else { $type=$calculation['type']; } $f=$this->default_fields[$key]; $total=$totals[$key]; switch($type) { case 'sum': /*foreach($posts as $p){ $meta=get_post_meta($p->ID, $key.$meta_marker,true); $total+=intval($meta); }*/ break; case 'average': /*foreach($posts as $p){ $meta=get_post_meta($p->ID, $key.$meta_marker,true); $total+=intval($meta); }*/ if(count($posts)==0){ $total=0; } else { $total=$total/count($posts); } break; } if(isset($calculation['ending'])) { $ending=$calculation['ending']; } else { $ending='currency'; } if($ending=='currency'){ $ending=$apm_settings['configs']['default_currency']; } update_post_meta($post_id, $key.'_'.$type.$meta_marker, $total); echo "
    '.$total.' '.$ending.'
    '; } } echo '
    '; } else { echo 'You need to specify a Post Type child'; } } public function getTableHeader($columns=false){ global $apm_settings; echo ''; if($columns==false){ echo ''; } else { foreach($columns as $column){ $f=$this->default_fields[$column]; $label=$f['label']; $label=str_replace("{{currency}}", $apm_settings['configs']['default_currency'], $label); if($column=="post_title"){ $label='Name'; } echo ''; } } echo ' '; } public function getTableFooter($columns=false){ global $apm_settings; echo ''; if($columns==false){ echo ''; } else { foreach($columns as $column){ $f=$this->default_fields[$column]; $label=$f['label']; $label=str_replace("{{currency}}", $apm_settings['configs']['default_currency'], $label); if($column=="post_title"){ $label='Name'; } echo ''; } } echo ' '; echo '
    Title Status Date'.$label.'
    Title Status Date'.$label.'
    '; } public function setUploadField($config) { global $post,$meta_marker; $custom = get_post_custom($post->ID); $download_id = get_post_meta($post->ID, $config['field'].$meta_marker, true); // echo '-----------'.$download_id; $download_id_arr=false; if(strpos($download_id, '*****')>-1){ $download_id_arr=explode('*****',$download_id); $download_id=$download_id_arr[0]; } echo '
    '; echo $config['before_field']; echo ''; echo $this->setLabel($config); $del_image = WP_PLUGIN_URL.'/'.WP_PLUGIN_FOLDER.'/img/block_16.png'; $add_image = WP_PLUGIN_URL.'/'.WP_PLUGIN_FOLDER.'/img/plus_16.png'; echo '
    '; $upload_field_display=""; /*if(!empty($download_id) && $download_id != '0') { $f=wp_get_attachment_url($download_id); $fa=explode('/',$f); $f=$fa[count($fa)-1]; $img=wp_get_attachment_url($download_id); $imglow=strtolower($img); echo '
    '; if(strpos($imglow,'.jpg')>-1 or strpos($imglow,'.png')>-1 or strpos($imglow,'.gif')>-1 ){ echo "
    "; } echo ' '.__('View file').': '. $f.'
    ';// $upload_field_display=' display:none '; }*/ $upload_field_display=$this->handleAddFileAttach($download_id,$config); echo '
    '; if($config['allow_multi_files']==true){ if($download_id_arr!==false){ for($i=1;$i'; if(strpos($imglow,'.jpg')>-1 or strpos($imglow,'.png')>-1 or strpos($imglow,'.gif')>-1 ){ echo "
    "; } echo ' '.__('View file').': '. $f.'
    ';// }*/ $this->handleAddFileAttach($download_id,$config,'sub'); } } echo '
    '; echo '
    Add more files
    '; } else { echo '
    '; } $this->getDescription($config); echo $config['after_field'].''; } public function handleAddFileAttach($download_id,$config,$filetype='main') { $del_image = WP_PLUGIN_URL.'/'.WP_PLUGIN_FOLDER.'/img/block_16.png'; $path_image = WP_PLUGIN_URL.'/'.WP_PLUGIN_FOLDER.'/img/'; $new_window_image = WP_PLUGIN_URL.'/'.WP_PLUGIN_FOLDER.'/img/new_window_icon.gif'; $add_text_image = WP_PLUGIN_URL.'/'.WP_PLUGIN_FOLDER.'/img/document_pencil_16.png'; $help_descr_layer_image = WP_PLUGIN_URL.'/'.WP_PLUGIN_FOLDER.'/img/bugsqa_16.png'; $upload_field_display=''; if(!empty($download_id) && $download_id != '0') { $f=wp_get_attachment_url($download_id); $fa=explode('/',$f); $f=$fa[count($fa)-1]; $filen=wp_get_attachment_url($download_id); if($config['image_resize']!==false){ $filen_arr=explode('.',$filen); $filen_arr_thumb=$filen_arr; $filen_arr_zoom=$filen_arr; $filen_arr_thumb[count($filen_arr)-2]=$filen_arr_thumb[count($filen_arr)-2].'_thumb'; $filen_thumb=implode('.',$filen_arr_thumb); $filen_arr_zoom[count($filen_arr)-2]=$filen_arr_zoom[count($filen_arr)-2].'_zoom'; $filen_zoom=implode('.',$filen_arr_zoom); } else { $filen_zoom=$filen; $filen_thumb=$filen; } $filenlow=strtolower($filen); $filenupp=strtoupper($filen); $filenextarr=explode(".",$filen); $ext=$filenextarr[count($filenextarr)-1]; $extlow=strtolower($ext); echo '

    '; if(strpos($filenlow,'.jpg')>-1 or strpos($filenlow,'.png')>-1 or strpos($filenlow,'.gif')>-1 ){ if($config['image_resize']==false){ echo "
    "; } else { echo "
    "; } } echo ''. $f.''; echo '
    '." ".' '; if($filetype=='main'){ $type="main"; } else if($filetype=='sub'){ $type="added"; } echo ' '; if($filetype=='main'){ echo ''; } else if($filetype=='sub'){ echo ''; }// $file_post=get_post($download_id); echo ' File name:'.$f.'.
    Title: '.$file_post->post_excerpt.'.
    Description: '.$file_post->post_content.'
    '; echo ' '; // echo "
    '; echo "

    "; echo '

    '; $upload_field_display=' display:none '; } return $upload_field_display; } public function setHTML($config) { echo $config['before_field']; echo $config['html']; $this->getDescription($config); echo $config['after_field']; } public function setTextArea($config) { global $meta_marker; $config['label_position']="top"; echo $config['before_field'].$this->setLabel($config); echo ''; $this->getDescription($config); echo $config['after_field']; } public function setRTEditor($config) { global $meta_marker; $config['label_position']="top"; echo $config['before_field']; echo $this->setLabel($config); echo "
    "; echo ' '; echo ''; $this->getDescription($config); echo "
    "; echo $config['after_field']; } public function setRadio($config) { global $meta_marker; $options=$config['options']; if ( is_array($options) ) { } else { $options=explode(';',$options); } if ( is_array($options) ) { echo $config['before_field'].$this->setLabel($config); foreach ($options as $key => $value) { echo " $value "; } $this->getDescription($config); echo $config['after_field']; } } public function setCheckbox($config) { global $meta_marker; $width=intval(100/$config['total_width']*$config['widthli'])-2; echo '
  • '.$this->setLabel($config); if($config['label_width_perc']>0){ echo '
    '; } echo ''; if($config['label_width_perc']>0){ echo '
    '; } $this->getDescription($config); echo '
  • '; } public function setSelect($config) { global $meta_marker; $widthli=intval(100/$config['total_width']*$config['widthli'])-2; $new_window_image = WP_PLUGIN_URL.'/'.WP_PLUGIN_FOLDER.'/img/new_window_icon.gif'; $options=$config['options']; if ( is_array($options) ) { } else { $options=explode(';',$options); } if ( is_array($options) ) { $null_value=false; $use_none=false; $multiselect=false; $advanced_ui=false; $select_type='default'; if(isset($config['field_config']) ){ if(isset($config['field_config']['use_values']) && $config['field_config']['use_values'] = true ){ $select_type='use_values'; } if(isset($config['field_config']['autoid']) && $config['field_config']['autoid'] = true ){ $select_type='autoid'; } if(isset($config['field_config']['post_type']) ){ $select_post_type=$config['field_config']['post_type']; $select_type='use_values_posttype'; $posts_list= $this->get_posts_list_alone($select_post_type); $options=array(); foreach ( $posts_list as $pos) { $options[$pos->ID]=$pos->post_title; } } if(isset($config['field_config']['null_value']) && $config['field_config']['null_value'] = true ){ $null_value=true; } if(isset($config['field_config']['use_none']) && $config['field_config']['use_none'] = true ){ $use_none=true; } if(isset($config['field_config']['multiselect']) && $config['field_config']['multiselect'] = true ){ $multiselect=true; } if(isset($config['field_config']['advanced_ui']) && $config['field_config']['advanced_ui'] = true ){ $advanced_ui=true; } } $selected = ''; if ( is_array($config['value']) ) { $value =$config['value']; } else { $value = (array) $config['value']; } if($multiselect){ $config['width'].=' style="width:700px;" '; $config['label_position']="top"; $sel .= ''; // } else { $sel .=''; if($config['label_width_perc']>0){ $sel .= ''; } echo '
  • '; echo $this->setLabel($config); $add_image = WP_PLUGIN_URL.'/'.WP_PLUGIN_FOLDER.'/img/plus_16.png'; echo $sel; $addBtn= sprintf( ' %s', esc_url( add_query_arg( array( 'post_type' => $select_post_type), 'post-new.php' ) ), "Add" ); if(isset($_GET['action']) and $_GET['action']=='edit' and $multiselect==false and $select_type=='use_values_posttype'){// echo $addBtn; $jumpBtn= '
    '.sprintf( '%s', esc_url( add_query_arg( array( 'action' => 'edit', 'post' => $selectedValue), 'post.php' ) ), "" ); $jumpBtn.=" ".sprintf( '%s', esc_url( add_query_arg( array( 'action' => 'edit', 'post' => $selectedValue), 'post.php' ) ), _('Open the selected parent article') ); //echo var_dump($value[0]); if(isset($value[0]) and ($value[0]=='none' or $value[0]=='' )){ } else { if(isset($config['field_config']['link_parent']) and $config['field_config']['link_parent']==false){ } else { echo $jumpBtn; } } } else if(!isset($_GET['action']) and $multiselect==false and isset($config['field_config']['force_add_btn']) and $config['field_config']['force_add_btn']==true){ echo $addBtn; } echo "
    "; $this->getDescription($config); echo '
  • '; } } function get_posts_list_titles($posts_list,$make_link=false){ $str=''; foreach ($posts_list as $key => $value) { if($make_link==true){ $str.= sprintf( '%s', esc_url( add_query_arg( array( 'post' => $value->ID,'action' => 'edit'), 'post.php' ) ),$value->post_title).' | '; } else { $str.=$value->post_title.' | '; } } $str=substr($str,0,strlen($str)-2); if($str==""){ $str="None"; } return $str; } function get_posts_list_alone($post_type){ global $post, $wpdb; $query = "SELECT post_title, ID FROM $wpdb->posts ". "WHERE post_type='".$post_type."' AND post_status='publish' "; $posts_list= $wpdb->get_results($query); return $posts_list; } function get_highest_value($post_type,$field){ global $post, $wpdb,$meta_marker; $query = "SELECT MAX(meta_value) as max FROM $wpdb->posts LEFT JOIN $wpdb->postmeta ON $wpdb->posts.ID = $wpdb->postmeta.post_id WHERE post_type='".$post_type."' AND post_status='publish' AND wp_postmeta.meta_key='".$field.$meta_marker."' "; $posts_list= $wpdb->get_results($query); return $posts_list[0]->max; } function get_posts_list_with_meta($post_type,$post_id,$meta_key){ global $post, $wpdb,$meta_marker; $query = "SELECT * FROM $wpdb->posts LEFT JOIN $wpdb->postmeta ON $wpdb->posts.ID = $wpdb->postmeta.post_id WHERE $wpdb->posts.post_type = '$post_type' AND wp_postmeta.meta_key='".$meta_key.$meta_marker."' AND wp_postmeta.meta_value='$post_id' AND ($wpdb->posts.post_status = 'publish' OR $wpdb->posts.post_status = 'draft') ORDER BY post_title"; $posts_list= $wpdb->get_results($query); // echo $query; return $posts_list; } public function setLabel($config) { global $apm_settings; if($config['label']==''){ return; } switch($config['label_position']){ case 'left': $label_br=''; break; case 'top': $label_br='
    '; break; } $req=''; if($config['required']){ $req='*'; } switch($config['label_type']){ case 'regular': $labl= ' '.$label_br; //return ' '.$label_br; break; case 'inline': $style=' style="" '; if($config['label_width']!==150) { $style=' style="width:'.$config['label_width'].'px; display:inline; " '; } if($config['label_width_perc']!==0) { $style=' style="width:'.$config['label_width_perc'].'%; float:left;" '; } $labl= ' '.$label_br; //return ' '.$label_br; break; default: //return ' '.$label_br; $labl= ' '.$label_br; break; } $labl=str_replace('{{currency}}',$apm_settings['configs']['default_currency'],$labl); if($config['hide_label']==true){ $labl=''; } return $labl; } } }