/** * Render an input password element. * * The element will have an id like: "password-$name" * * @param mixed parameters: * - id: string * - style: string * - hidden: boolean * - content: string * @param bool return or echo flag * * @return string HTML code if return parameter is true. */ function print_div($options, $return = false) { $output = '<div'; //Valid attributes (invalid attributes get skipped) $attrs = array("id", "style", "class"); if (isset($options['hidden'])) { if (isset($options['style'])) { $options['style'] .= 'display:none;'; } else { $options['style'] = 'display:none;'; } } foreach ($attrs as $attribute) { if (isset($options[$attribute])) { $output .= ' ' . $attribute . '="' . safe_input_html($options[$attribute]) . '"'; } } $output .= '>'; $output .= isset($options['content']) ? $options['content'] : ''; $output .= '</div>'; if ($return) { return $output; } else { echo $output; } }
function users_save_text_message($message = false, $type = 'message') { global $config; global $dir; global $id; $file_global_counter_chat = $dir . '/incident.' . $id . '.global_counter.txt'; $log_chat_file = $dir . '/incident.' . $id . '.log.json.txt'; $return = array('correct' => false); $id_user = $config['id_user']; $user = get_db_row_filter('tusuario', array('id_usuario' => $id_user)); $message_data = array(); $message_data['type'] = $type; $message_data['id_user'] = $id_user; $message_data['user_name'] = $user['nombre_real']; $message_data['text'] = safe_input_html($message); //The $message_data['timestamp'] set when adquire the files to save. //First lock the file $fp_global_counter = @fopen($file_global_counter_chat, "a+"); if ($fp_global_counter === false) { echo json_encode($return); return; } //Try to look MAX_TIMES times $tries = 0; while (!flock($fp_global_counter, LOCK_EX)) { $tries++; if ($tries > MAX_TIMES) { echo json_encode($return); return; } sleep(1); } @fscanf($fp_global_counter, "%d", $global_counter_file); if (empty($global_counter_file)) { $global_counter_file = 0; } //Clean the file ftruncate($fp_global_counter, 0); $message_data['timestamp'] = time(); $message_data['human_time'] = date($config['date_format'], $message_data['timestamp']); $global_counter = $global_counter_file + 1; $status = fwrite($fp_global_counter, $global_counter); if ($status === false) { fclose($fp_global_counter); echo json_encode($return); return; } else { $text_encode = @file_get_contents($log_chat_file); $log = json_decode($text_encode, true); $log[$global_counter] = $message_data; $status = file_put_contents($log_chat_file, json_encode($log)); fclose($fp_global_counter); $return['correct'] = true; echo json_encode($return); } return; }