欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

王者大陆运营的自己亲自做的模块 execself

shiping1 的头像

<?php

 
function execself_init() 
{
$node = menu_get_object();
if(!empty($node) && $node->type=='event_wzdl')
{
$rowObjs = _getToDevNids($node->nid,'asc','limit 0,1');
//第一次递交时,递交人是本人,递交的部门是 to_development的title
$node->firstSendPerson = $rowObjs[0]->name;
$node->firstSendDepart = user_load($rowObjs[0]->uid)->profile_department;
}
}
 
 
function _getDevArr()
{
  $query = "SELECT global_settings FROM {content_node_field} where field_name='field_to_development' limit 0,1";
  $queryResult = db_query($query);
 
  $result =db_fetch_object($queryResult);
  $global_settings  = $result->global_settings;
  $arrGlobal_settings = unserialize($global_settings);
  $allow_values = $arrGlobal_settings['allowed_values'];
  
  $allow_valuesArr = explode('
',$allow_values);
  $newAllow_valuesArr = array();
  foreach($allow_valuesArr as $key=>$value)
  {
    $arr = explode('|',$value);
    $newAllow_valuesArr[$arr[0]] = $arr[1];    
  }
  return $newAllow_valuesArr;
   
 
}
 
function _getDevByEn($index)
{
  /*$arr = array('kefubu'=>'客服部',
'jiankongbu'=>'监控部',
'yunyingbu'=>'运营部',
'yunweibu'=>'运维部',
'pingtaibu'=>'平台部',
'jifenpingtai'=>'计费平台',
'kefuguanbi'=>'客服关闭'    
  );
  return $arr[$index];*/
 
  $devArr =  _getDevArr();
  return $devArr[$index];
}
 
 
 
//我们再插入一条到哪个部门的数据
function execself_nodeapi(&$node, $op, $a3 = null , $a4 = null){
if($op=='insert' && $node->type == 'event_wzdl' ){
  // drupal_set_message("RRRRRR");
$toDevnode = (object)$toDevnode;
$toDevnode->uid = $node->uid;
$toDevnode->type = 'to_development';
$toDevnode->field_event[0][nid] =  $node->nid;
 
//print_r($node->field_to_development[0]['value']);
$toDevnode->title = _getDevByEn($node->field_to_development[0]['value']);
$toDevnode->field_send_person[0]['value'] =  $node->field_send_person[0]['value'];
$toDevnode->field_zhuanjian_desc[0]['value'] = '第一次提交到'.$toDevnode->title;
//$newNode =devel_render_object('node', $node) ;//这个方法不行
//exit;
node_save($toDevnode);
}
}
 
 
 
 
/**
* Implementation of hook_form_alter().
* 创建隐藏字段的方法
*/
function execself_form_alter(&$form, &$form_state, $form_id) {
  if (isset($form['type']) && isset($form['#node'])) {
     ### Make a CCK field becoming a hidden type field.
    // ### Use this check to match node edit form for a particular content type.
    if ($form_id === 'event_wzdl_node_form') {
     //下面注掉的两行禁用title字段
     // $form['title']['#disabled'] = true;
      //$form['title']['#attributes']['class'] = 'my_class';
      global $user;
      //var_dump($user->name);
      /*$form['field_send_person'][0]= array(
        '#type'=>'textfield',
        '#title'=>'递交人',
        '#size'=>20,
        '#value'=>$user->name
      );*/
      
      $form['field_zhuanjian_chuli'][0]['#default_value']['value'] = '0';  
      $form['field_chuli_person'][0]['#default_value']['value'] = '';  
      $form['#after_build'] = array('_test_set_cck_field_to_hidden');
 
 // 调试时候,打印$form出来看下
      //print '<pre>'. check_plain(print_r($form, 1)) .'</pre>'; 
      
      
      
      //增加class
      $form['#attributes'] = array('class' => 'event-wzdl-form');      
         // 修改form跳转路径
      $form['#redirect'] = 'my_event_list_page';
      
      //$form['field_send_person'][0]['value']['#attributes']['disabled'] = 'disabled';

      //$form['field_send_person'][0]['#disabled'] = true;

//增加 js 功能 

      drupal_add_js('$("#edit-field-send-person-0-value").attr("readonly","true");', 'inline', 'footer');
      
      drupal_add_js('$("#edit-field-play-time-0-value-datepicker-popup-0").attr("autocomplete","off");', 'inline', 'footer');
    }
  }
  if ($form_id == 'views_exposed_form' && $_GET['q']=='search_event_list_page') {
  //drupal_add_js('alert(1111);', 'inline', 'footer');
   //drupal_add_js('alert("Hello!")', 'inline');   
 $form['field_zhuanjian_chuli_value_many_to_one']['#options']['All'] = '请选择';
 $form['field_zhuanjian_chuli_value_many_to_one']['#options']['0'] = '未处理';
 $form['field_zhuanjian_chuli_value_many_to_one']['#options']['1'] = '已处理';
 $form['field_zhuanjian_chuli_value_many_to_one']['#options']['2'] = '已关闭';
    
 $form['submit']['#value'] ='搜索表单';   
 $form['#attributes'] =  array('class' => 'search_event_form');
 drupal_add_js('$("select.form-select option[index=0]").text("请选择");', 'inline', 'footer');
  //让它先添加一个(因为这个当前用户是个例外);
 drupal_add_js('$("#edit-uid-current").prepend("<option  value=\"All\">请选择</option>")','inline', 'footer');
 drupal_add_js('$("#edit-field-zhuanjian-chuli-value-many-to-one").prepend("<option  value=\"All\" >请选择</option>")','inline', 'footer');
 drupal_add_js('$("select.form-select option[index=1]").remove();', 'inline', 'footer');
 
 drupal_add_js('$("#edit-field-possible-dates-value-value-datepicker-popup-0").attr("autocomplete","off");', 'inline', 'footer');
 drupal_add_js('$("#edit-field-possible-dates-value2-value-datepicker-popup-0").attr("autocomplete","off");', 'inline', 'footer');
  
  
  
  //下面这个没有用
   /*edit-field-youxi-name-value-many-to-one
   edit-field-zhuanjian-chuli-value-many-to-one
 edit-field-youxi-daqu-value-many-to-one
 edit-field-youxi-server-value-many-to-one
 edit-field-visited-reason-value-many-to-one
 edit-field-event-type-value-many-to-one
 edit-field-to-development-value-many-to-one*/
  }
  if ($form_id == 'views_exposed_form' && $_GET['q']=='admin/user/user/custom_user_list') {
      $form['select']['#title'] = '批量操作';
      $form['submit']['#value'] = '查询';
      $str = 'if($("select.form-select option[index=0]").val()=="All") $("select.form-select option[index=0]").text("请选择");';
 drupal_add_js($str, 'inline', 'footer');
  }
  if ($form_id == 'views_bulk_operations_form__1' && $_GET['q']=='admin/user/user/custom_user_list') {
  $form['select']['#title'] = '批量操作';
    $form['select']['submit']['#value'] = '执行';
  }
}
 
/**
 * 
 * @param
 * @return
*/
function _test_set_cck_field_to_hidden($form, &$form_state) {
  $form['field_zhuanjian_chuli'][0]['value']['#type'] = 'hidden';  
  $form['field_zhuanjian_chuli'][0]['#value']['value'] = '0'; 
  $form['field_chuli_person'][0]['value']['#type'] = 'hidden';  
  $form['field_chuli_person'][0]['#value']['value'] = '';   
  
   
  
  // $form['field_zhuanjian_chuli'] = array( '#type' => 'hidden', '#value' => $club);
  //$form['field_zhuanjian_chuli'][0]['#value'] ='1';
  //$form['field_zhuanjian_chuli'][0] = array( '#type' => 'text', '#value' => '1');
  return $form;
}
 
 
//下面这个没用
function execself_node_presave($node) {
  // you may also wan't to check the 'status' of the node
  if($node->nid && $node->type == 'event_wzdl') {
     $node->title=time();
  }
  drupal_set_message('GGGGGGGGG');
  return $node;
}
 
//得到到部门的对象的object的数组
function _getToDevNids($nid,$orderway,$limit='')
{
  $sql ="select no.nid from {node} no inner join {content_field_event} as rel on  rel.nid=no.nid  
         where rel.field_event_nid='%d' order by rel.nid $orderway $limit ";
    $resultToDev = db_result(db_query($sql,$nid)); 
  $result = db_query($sql,$nid); 
  //这里求的是所有的关于这个event 所转交的产生的记录 对象
  while($rowObj = db_fetch_object($result)) {
  $rowNids[] = $rowObj->nid;  
  } 
   foreach($rowNids as $row){
     $rowObjs[] =  node_load($row);
  }
  return $rowObjs;
}
function _getSameValue($arr1,$arr2)
{
foreach ($arr1 as $value)
{
 if (in_array($value,$arr2))
 {
   return $value;
 }
}
//不存在的话返回 管理员
return '管理员';
}
 
//设置表单处理
function _setFormChuli(&$form,$node,$nodeToDev)
{  
        //第一次递交时,递交人是本人,递交的部门是 to_development的title
        //最后处理时,处理人就是最后一个处理人的name,处理的部门就是处理人所在的部门
    $form['chuli-close']['aaaa'] = array(
     '#type' => 'markup', 
     '#value' => '<div class="chuili-reslut">递交人: '.'<font color=green>'.$node->field_send_person[0]['value'].'</font></div>',
     '#attributes'=>array('class'=>'showchuliresult')
    );
    $form['chuli-close']['bbbb'] = array(
     '#type' => 'markup', 
     '#value' => '<div class="chuili-reslut">递交部门: '.'<font color=green>'.user_load($node->uid)->profile_department.'</font></div>',
     '#attributes'=>array('class'=>'showchuliresult')
    );
    $form['chuli-close']['cccc'] = array(
     '#type' => 'markup', 
     '#value' => '<div class="chuili-reslut">处理人: '.'<font color=green>'.user_load($nodeToDev->uid)->name.'</font></div>',
     '#attributes'=>array('class'=>'showchuliresult')
    );
    $form['chuli-close']['dddd'] = array(
     '#type' => 'markup', 
     '#value' => '<div class="chuili-reslut">处理部门: '.'<font color=green>'.user_load($nodeToDev->uid)->profile_department.'</font></div>',
     '#attributes'=>array('class'=>'showchuliresult')
    );
    $form['chuli-close']['eeee'] = array(
     '#type' => 'markup', 
     '#value' => '<div class="chuili-reslut">处理说明: '.'<font color=green>'.$nodeToDev->field_zhuanjian_desc[0]['value'].'</font></div>',
     '#attributes'=>array('class'=>'showchuliresult')
    );
}
 
//这里填写的是增加转交或处理
function zhuanjian_chuli_form(&$form_state, $node)
{
    //var_dump($devArr);exit;
    global $user;
    //var_dump("AAAAAAAAAA");
    //var_dump($node->field_zhuanjian_chuli[0]['value']);exit;
    $form['#attributes'] =  array('class' => 'zhuanjian_chuli_form');
    
    //事件对象
    $nodeToDevs = _getToDevNids($node->nid,'asc','limit 0,1');
    $nodeToDevsStart = $nodeToDevs[0];
    
    $nodeToDevs = _getToDevNids($node->nid,'desc','limit 0,1');
    $nodeToDevEnd=$nodeToDevs[0];
    //处理状态时
    if($node->field_zhuanjian_chuli[0]['value']==1){
    $form['#attributes']= array('class' => 'threeradioform');
        $form['chuli-close'] = array(
     '#type' => 'fieldset', 
     '#title' => '<font color=green>事件已处理</font>',
     '#value' => '<font color=green></font>',
     '#attributes'=>array('class'=>'showchuliresult')
    );
    _setFormChuli($form,$nodeToDevsStart,$nodeToDevEnd);
   
   
    //有递交表单的权限
    //if(user_access('处理 客服部事件')){
    $items[] = l('快捷提交', 'node/addwzdlevent/'.$node->nid.'/create',array('attributes' => array('title' => '快捷递交')));
    $form['chuli-close']['links'] = array('#value' => theme('item_list', $items,'','ul',array('class'=>'my-list-class'))); 
    //}
    return $form;
    }
    //关闭状态时
    if($node->field_zhuanjian_chuli[0]['value']==2)
    {  
        $form['#attributes']= array('class' => 'threeradioform');
    $form['chuli-close'] = array(
     '#type' => 'fieldset', 
     '#title' => '<font color=red>事件已关闭</font>',
     '#value' => '<font color=red></font>',
     '#attributes'=>array('class'=>'showchuliresult')
    );    
    _setFormChuli($form,$nodeToDevsStart,$nodeToDevEnd);
    return $form;
    }
     
    //是关闭状态 但是 没有关闭权限的人看到的只能到此为止
    /*if($node->field_zhuanjian_chuli[0]['value']==2 && !user_access('处理 关闭事件'))
    {
       
    }*/
    $form['field_zhuanjian_chuli'] = array(
'#type' => 'radios',
'#title' => '转交还是递送',
//'#description' =>'让用户选择转交还是递送',
'#options' => array(
0=>'转交',//表单中radio 值 就是键 
1=>'处理',
2=>'关闭'
),
'#default_value' => $node->field_zhuanjian_chuli[0]['value']
    );
   //下面这个为测试
   //假如为关闭 ,就禁用关闭radio
//$form['field_zhuanjian_chuli']['#options'][2]='disabled';
    // drupal_add_js('alert("Hello!")', 'inline');
    //执行到这里 没有权限关闭状态时 禁用关闭
    if(!user_access('处理 关闭事件')){
      drupal_add_js('$("#edit-field-zhuanjian-chuli-2").attr("disabled","disabled");', 'inline', 'footer');
           
    }
    //假如是处理时 并且此人没有禁用关闭状态的权限时  也禁用转交
    if($node->field_zhuanjian_chuli[0]['value']==1 && !user_access('处理 关闭事件')){
      drupal_add_js('$("#edit-field-zhuanjian-chuli-0").attr("disabled","disabled");', 'inline', 'footer');
    }
$form['title'] = array(
'#type' => 'select',
'#options' => _getDevArr()
//'#title' => '联系电话',
);
    $form['field_send_person'] = array(
'#type' => 'textfield',
'#title' => '转交人' ,
'#size' => '20',
'#default_value' => $user->name,
'#attributes'=>array(
  'readonly'=>true
)
);
$form['field_zhuanjian_desc'] = array(
'#type' => 'textarea',
'#title' => '转交或处理说明',
'#rows' => 3
);
 
$form['submit']   = array('#type' => 'submit', '#value' => '确认提交');
switch ($node->field_to_development[0]['value'])
{
case 'kefubu':
 !user_access('处理 客服部事件') && $form['submit']['#disabled'] = true;  
break;
 
case 'pingtaibu':
 !user_access('处理 平台部事件') && $form['submit']['#disabled'] = true;
  break;
 
case 'jiankongbu':
 !user_access('处理 监控部事件') && $form['submit']['#disabled'] = true;
break;
 
case 'yunyingbu':
  !user_access('处理 运营部事件') && $form['submit']['#disabled'] = true;
break;
 
case 'yunweibu':
  !user_access('处理 运维部事件') && $form['submit']['#disabled'] = true;
break;
 
case 'jifenpingtai':
  !user_access('处理 计费平台事件') && $form['submit']['#disable'] = true;
break;
 
 
}
 
 
$form['event_wzdl_nid'] = array('#type' => 'value', '#value' => $node->nid);
 
 
 
return $form;
}
 
 
//表单函数_validate 验证类似于钩子函数的回调函数
function zhuanjian_chuli_form_validate(&$form, &$form_state)
{
    /**
   * 用户提交的所有数据在 $form_state['values'] 之中,相当于 $_POST
   */
// form_set_error('',$form_values['name']);
 $field_zhuanjian_chuli  = $form_state['values']['field_zhuanjian_chuli'];
 if($field_zhuanjian_chuli==0)//关闭时不需要填写到部门
 {
   
   if($form_state['values']['title'] == '')
 {
   form_set_error('title','你必须选择部门名称');
 }
 if($form_state['values']['field_zhuanjian_desc'] == '')
 {
   form_set_error('field_zhuanjian_desc','你必须输入转交或处理说明');
 }
 }
 else {
   if($form_state['values']['field_zhuanjian_desc'] == '')
 {
   form_set_error('field_zhuanjian_desc','你必须输入转交或处理说明');
 }
 }
}
 
//表单函数_submit 提交函数
function zhuanjian_chuli_form_submit(&$form, &$form_state)
{
/**
    * 用户提交的所有数据在 $form_state['values'] 之中,相当于 $_POST
    */
    global $user;
    $nid = $form_state['values']['event_wzdl_nid'];
    $node =  node_load($nid);  
   
    //这里是有权限的人从关闭改变到其它状态 
   
  $toDevnode = (object)$toDevnode;
$toDevnode->uid = $user->uid;
$toDevnode->type = 'to_development';
$toDevnode->field_event[0][nid] =  $nid;
 
//print_r($node->field_to_development[0]['value']);
 
$toDevnode->title = _getDevByEn($form_state['values']['title']);
 
$toDevnode->field_send_person[0]['value'] =  $form_state['values']['field_send_person'];
$toDevnode->field_zhuanjian_desc[0]['value'] = $form_state['values']['field_zhuanjian_desc'];
//$newNode =devel_render_object('node', $node) ;//这个方法不行
//exit;
 
$node->field_zhuanjian_chuli[0]['value'] = $form_state['values']['field_zhuanjian_chuli'];
$node->field_to_development[0]['value'] = $form_state['values']['title'];
 
//关闭的时候
if($form_state['values']['field_zhuanjian_chuli']=='2'){
   $node->field_chuli_person[0]['value'] = $form_state['values']['field_send_person'];
$node->field_to_development[0]['value'] = '';
  $toDevnode->title = '关闭事件,不转交';
 
//处理的时候 ,处理人的名字 就是发送人吧 ;此时发送部门应该就是客服关闭吧
if($form_state['values']['field_zhuanjian_chuli']==1){
$node->field_chuli_person[0]['value'] = $form_state['values']['field_send_person'];
$node->field_to_development[0]['value'] = '';
$toDevnode->title = '已处理';
//$toDevnode->title = _getDevByEn('kefuguanbi');
}
node_save($toDevnode);
node_save($node);
 
if ($toDevnode->nid) 
{
   if($form_state['values']['field_zhuanjian_chuli']==2){
    drupal_set_message('关闭事件成功');
   }
   else {
    drupal_set_message('转交或处理成功');
    drupal_set_message('已转到'.$toDevnode->title);
   }
}
else
{
drupal_set_message('转交或处理失败,请重新来一次。', 'error');
}
   
}
 
function getCurrZjRecord()
{
  //global $node;
  $node = menu_get_object();
  if($node->type != 'event_wzdl'){
     return '';
  }
  /*$sql = "select no.title,person.field_send_person_value,no.created,dev.field_zhuanjian_desc_value from {node} as no 
  inner join {content_field_event} as rel
          on rel.nid=no.nid  left join {content_type_to_development} as dev 
          on no.nid=dev.nid  inner join content_field_send_person as person 
          on no.uid=person.nid  
          where rel.field_event_nid='%d' order by rel.nid asc";
  $result = db_query($sql,$node->nid); 
   
  while ($rowObject = db_fetch_object($result))
  {
//$rows['time']= date('Y-m-d H:i:s',$rowObject->created);
$rows[]= array($rowObject->field_send_person_value,$rowObject->title,
date('Y-m-d H:i:s',$rowObject->created),$rowObject->field_zhuanjian_desc_value);
  }*/
  
  $rowObjs= _getToDevNids($node->nid,'asc');
  
  //反正转交不含第一个
  array_splice($rowObjs, 0, 1);
  
  //如果是处理 或关闭 去掉最后一个
  if($node->field_zhuanjian_chuli[0]['value']==1 || $node->field_zhuanjian_chuli[0]['value']==2)
  {
     array_splice($rowObjs, count($rowObjs)-1);
  }
  
  foreach($rowObjs as $rowObj){
  $rows[] = array($rowObj->field_send_person[0]['value'],user_load($rowObj->uid)->profile_department,$rowObj->title,
  date('Y-m-d H:i:s',$rowObj->created),$rowObj->field_zhuanjian_desc[0]['value'],);
  }
  $headers = array('转交人','转交部门','转交到部门','时间','转交说明');
  $content = theme('table',$headers, $rows);
  //return $sql;
  return $content;
  
/* $query = "select nid,title,created from {node}";
$queryResult = db_query_range($query, 0 ,10);
$links = array();
while ($node = db_fetch_object($queryResult))
{
$links[] = l($node->title,'node/'.$node->nid);
}
$block['content'] = theme('item_list', $links);
$block['subject'] = '我的第二个block';*/
}
 
 
//自定义区块所放的内容
function execself_block($op='list',$delta=0)
{
//return array();
if ($op=='list'){
$blocks[0]['info'] = '历史转交记录';
return $blocks;
}
else if($op == 'view'){
 if($delta==0){
  $blocks['subject'] = '历史转交记录';
$blocks['content'] = getCurrZjRecord();  
   return $blocks;
 } 
}
/*switch ($op)
{
case 'list' :
$block[0]['info'] = '历史转交记录';
return $block;
 
case 'view' :
switch ($delta)
{
case 0 :
  $block['subject'] = '历史转交记录';
$content = getCurrZjRecord();
$block['content'] = getCurrZjRecord();
break;
}
return $block;
break;
}*/
}
 
 
//定义权限 仅仅指明什么权限对这个模块可用
function execself_perm(){
      return array('处理 关闭事件','处理 客服部事件',
      '处理 平台部事件','处理 监控部事件','处理 运营部事件',
      '处理 运维部事件','处理 计费平台事件','处理 关闭事件'); 
}
 
//function execself_form_alter(&$form, &$form_state, $form_id) {
    // 先判断form id,只修改某form
    //if ($form_id == 'event_wzdl_node_form') {
        // 调试时候,打印$form出来看下
        //print '<pre>'. check_plain(print_r($form, 1)) .'</pre>'; 
        
        // 修改form跳转路径
      //  $form['#redirect'] = url('xxoo');
    //}
//}
 
function _getTotalRoles()
{
 return array('jiankongbu'=>'监控部','jifenpingtai'=>'计费平台',
'kefubu'=>'客服部','kefuguanbi'=>'客服关闭','pingtaibu'=>'平台部',
'yunweibu'=>'运维部','yunyingbu'=>'运营部');
 
}
 
//这里用  hook_views_pre_view 过进行过滤
 
function execself_views_pre_view(&$view, &$display_id, &$args)
{
if($view->name == 'event_list') 
{
global $user;
////部门中文值
//db_result是直接取到第一个值
$departValue = db_result(db_query("select pro_val.value from profile_values as pro_val
where pro_val.uid='%d' and pro_val.fid=2 ", $user->uid));//fid为2就是表示所属部门
$departArrs = _getDevArr();
$departKey = array_keys($departArrs,$departValue);  //得到部门的英文键  en|cn 英文是键,中文是值
   $filters = $view->display_handler->get_option('filters');
    //var_dump($filters['field_to_development_value']['value']);exit;
   $filters['field_to_development_value']['value'] = $departKey;
   $view->display_handler->override_option('filters', $filters);
}
}
/*function execself_views_pre_view(&$view, &$display_id, &$args)
{
if($view->name == 'event_list') 
{
$totalRoles=_getTotalRoles();
global $user;
$roles=$user->roles;
$accessRoleKeys=array();
foreach($totalRoles as $keyRole=>$keyValue)
{
 if(in_array($keyValue,$roles))
 {
   //事实上只有一个其实就是$accessRoleKeys[0];
   $accessRoleKeys[] = $keyRole;
 }
}
   $filters = $view->display_handler->get_option('filters');
    //var_dump($filters['field_to_development_value']['value']);exit;
   $filters['field_to_development_value']['value'] = $accessRoleKeys[0];
   $view->display_handler->override_option('filters', $filters);
}
}*/
 
//hook_menu
function execself_menu()
{
$items['/node/add/page/%'];
 
 
   $items['node/add/event-wzdl/%'] = array(
'title'=>'快捷递交',
'access arguments'=> array('recreate event-wzdl')  
);
 
return $items;
}
普通分类: