欢迎各位兄弟 发布技术文章
这里的技术是共享的
<?php
function custome_twenty_eight_self_installtion_menu()
{
$items['self_installation_add'] = array(
'title' => '',
'page callback' => 'custome_twenty_eight_self_installtion_self_installation_add',
'access arguments' => array('access content'),
);
return $items;
}
function custome_twenty_eight_self_installtion_self_installation_add()
{
// $sql = "select nid from node where type='self_installation_info' ";
// $all = db_query($sql)->fetchAll();
//
// foreach($all as $key=>$one)
// {
// $nid = $one->nid;
// $temp_node = node_load($nid);
// $temp_node->field_self_install_type['und'][0]['value'] = 'win_self_installation';
// node_save($temp_node);
//
// }
// exit;
// 获取原始的 POST 数据(JSON)
$jsonData = file_get_contents('php://input');
// 将 JSON 解码为 PHP 数组
$data = json_decode($jsonData, true);
$computer = $data['computer'];
$soft = $data['soft'];
$type = $data['type'];
$gh = $data['gh'];
$diqu = _my_node_jses_terminal_manager_diqu();
$ad_dn_info = _get_ad_info_from_ad($gh, array('dn'), $diqu);
//$ad_dn_info 的一个示例值为
// array(2) {
// ["count"]=>
// int(0)
// ["dn"]=>
// string(90) "CN=张三(11111111),OU=eeeeee,OU=cc-ddddd,OU=bbbbbDC=aaaaa,DC=com,DC=cn"
// }
if(empty($ad_dn_info)){
$xm = $gh;
}else{
if(_istrExistsIC($ad_dn_info['dn'],"(")){
$xm = substr($ad_dn_info['dn'], 3, stripos($ad_dn_info['dn'], '(') - 3);
}else if(_istrExistsIC($ad_dn_info['dn'],",")){
$xm = substr($ad_dn_info['dn'], 3, stripos($ad_dn_info['dn'], ',') - 3);
}else{
$xm = $ad_dn_info['dn'];
}
}
$max_created_time = time() - 28800; // 28800 = 3600*8 //同一个电脑,同一个软件,同一个工号,,,,这里要求上次安装的时间要小于 8小时,,才算 一个,,也就是更新 原来的node,,,,否则的话,算 增加一次安装
//判断同一个 子网 ip 下面 mac地址是否存在 ,如果有的话,就相当于更新,没有的话,就相当于创建吧
$temp_nid = db_query("select n.nid from node n inner join field_data_field_self_install_gh gh on n.nid=gh.entity_id
inner join field_data_field_self_install_computer computer on n.nid=computer.entity_id
inner join field_data_field_self_install_soft soft on n.nid=soft.entity_id
where n.type='self_installation_info'
and gh.bundle='self_installation_info' and gh.entity_type='node' and computer.bundle='self_installation_info' and computer.entity_type='node' and soft.bundle='self_installation_info' and soft.entity_type='node'
and n.created >= $max_created_time
and gh.field_self_install_gh_value=:gh and computer.field_self_install_computer_value=:computer and soft.field_self_install_soft_value=:soft ",
array(':gh' => $gh, ':computer' => $computer, ':soft' => $soft))->fetchField();
if (!empty($temp_nid)) {//假如存在的话
$one_node = node_load($temp_nid);
$one_node->created = time();//修改一下创建时间吧
} else {
$one_node = null;
$one_node = (object)$one_node;
}
$one_node->uid = 1;
$one_node->type = 'self_installation_info';
$one_node->title = '自助安装信息-' . time();
$one_node->field_self_install_gh['und'][0]['value'] = $gh;
$one_node->field_self_install_xm['und'][0]['value'] = $xm;
$one_node->field_self_install_computer['und'][0]['value'] = $computer;
$one_node->field_self_install_soft['und'][0]['value'] = $soft;
$one_node->field_self_install_type['und'][0]['value'] = $type;
node_save($one_node);
}
function custome_twenty_eight_self_installtion_views_exposed_form_validate($form, &$form_state)
{
$created = _removeCnEnSpace($form_state['values']['created']);
$created_1 = _removeCnEnSpace($form_state['values']['created']);
if ( !empty($created) && !preg_match('/^\d{4}-(0?[1-9]|1[0-2])-(0?[1-9]|[12][0-9]|3[01])$/', $created)) {
form_set_error('created', '开始日期格式不对,格式为'.date('Y-m-d'));
}
if (!empty($created_1) && !preg_match('/^\d{4}-(0?[1-9]|1[0-2])-(0?[1-9]|[12][0-9]|3[01])$/', $created_1)) {
form_set_error('created_1', '结束日期格式不对,格式为'.date('Y-m-d'));
}
}
//把日期中的 年-月-日 时:分:秒 全部转变成 年-月-日
function custome_twenty_eight_self_installtion_form_alter(&$form, &$form_state, $form_id)
{
if ('views_exposed_form' == $form_id && $_GET['q'] == 'list-self-installation-info')
{
$form['#validate'][] = 'custome_twenty_eight_self_installtion_views_exposed_form_validate';
}
}
////下面的这个 to_do_view block_2 似乎没有用到 看区块 http://jsfaq.luxshare-ict.com/admin/structure/block 是禁用了的
//function custome_twenty_eight_self_installtion_views_pre_view(&$view, &$display_id, &$args)
//{
//
// if(($view->name == 'list_self_installation_info') && ($display_id == 'page'))
// {
//// $filters = $view->display_handler->get_option('filters');
//// $export = kprint_r($filters, TRUE);
//// print $export;
// }
//
//}
//修改 视图的 SQL 语句 ,让 小于等于 2024-11-24 (事实上是 2024-11-24 00:00:00) ,,,真正应该是 2024-11-25 00:00:00
function custome_twenty_eight_self_installtion_views_query_alter(&$view, &$query)
{
if (($view->name == 'list_self_installation_info') && ($view->current_display == 'page'))
{
foreach($query->where[1]['conditions'] as $key=>$condition)
{
//这是结束日期,,,示例 " node.created < 1765382400 " 假如表单上结束日期是 2025-12-11 (也就是 2025-12-11 00:00:00 ) ,时间戳就是 1765382400,
//我们的意思事实上 的结束的真正时间是 2025-12-12 00:00:00 ,,,也就是在时间戳上面加上 24*3600秒
if(_istr_exists_ic($condition['field'],'node.created') && _istr_exists_ic($condition['field'],'<') && !_istr_exists_ic($condition['field'],'>='))
{
//数组如下
// array(3) {
// [0]=>
// string(12) "node.created"
// [1]=>
// string(1) "<"
// [2]=>
// string(10) "1765382400"
// }
$tmp_arr = explode(" ",$condition['field']);
$end_time = $tmp_arr[count($tmp_arr)-1];
$end_time = $end_time+86400 ; //86400 = 24*3600
$tmp_arr[count($tmp_arr)-1] = $end_time;
$condition['field'] = implode(" ",$tmp_arr);//转成字符串
$query->where[1]['conditions'][$key] = $condition;
}
}
}
}