</section> <section class="two_third last"> <?php get_currentuserinfo(); $user_id = $current_user->ID; if ($user_id == 0) { ?> <article class="content_ya_voto"> <p>Debe loguearse para poder votar.</p> </article> <?php } else { if (userYaVoto($post->ID, $user_id)) { ?> <article class="content_ya_voto"> <p>Usted a evaluado esta empresa.</p> </article> <?php } else { ?> <!-- Evaluar empresa --> <article class="content_evaluar_empresa"> <div class="titulo_evaluar_empresa"> <aside class="triangle-left"></aside> <h3>EVALUÁ A ESTA EMPRESA</h3> <div class="clearfix"></div> </div>
function ajax_voteop() { global $current_user; global $wpdb; get_currentuserinfo(); $user_id = $current_user->ID; $url = wp_get_referer(); $post_id = url_to_postid($url); $voto = $_POST['voto']; $mensaje = $_POST['mensaje']; $calidad = $_POST['calidad']; $cumplimiento = $_POST['cumplimiento']; $administrativos = $_POST['administrativos']; $check_empresa = $_POST['check_empresa']; /* ChromePhp::log($user_id); ChromePhp::log($post_id); ChromePhp::log($mensaje); ChromePhp::log($voto); ChromePhp::log($calidad); ChromePhp::log($cumplimiento); ChromePhp::log($administrativos); */ //validaciones $error_voto = false; $mensaje_error = ''; if ($check_empresa == 'false') { echo json_encode(array('vote_ok' => false, 'message' => __('Debe haber trabajado con esta empresa para poder calificarla.'))); die; } if ($voto == 0 or $calidad == 0 and $cumplimiento == 0 and $administrativos == 0) { echo json_encode(array('vote_ok' => false, 'message' => __('Debe elegir su voto y por lo menos una razón del mismo.'))); die; } if (is_numeric($voto) == false or is_numeric($calidad) == false or is_numeric($cumplimiento) == false or is_numeric($administrativos) == false) { $error_voto = true; } if ($voto > 0) { if ($calidad < 0) { $error_voto = true; } if ($cumplimiento < 0) { $error_voto = true; } if ($administrativos < 0) { $error_voto = true; } } else { if ($calidad > 0) { $error_voto = true; } if ($cumplimiento > 0) { $error_voto = true; } if ($administrativos > 0) { $error_voto = true; } } $mensaje_error = 'Ha habido un error con la votación, inténtelo de nuevo.'; if ($error_voto == true) { echo json_encode(array('vote_ok' => false, 'message' => __($mensaje_error))); die; } if ($mensaje == '') { echo json_encode(array('vote_ok' => false, 'message' => __('Debe dejar un comentario para votar.'))); die; } if (userYaVoto($post_id, $user_id)) { //ChromePhp::log('entré'); echo json_encode(array('vote_ok' => false, 'message' => __('Ya has votado a esta empresa.'))); die; } $result_insert = $wpdb->insert('f8c_vote_info', array('id_user' => $user_id, 'id_empresa' => $post_id, 'calidad_servicio' => $calidad, 'cumplimiento_plazos' => $cumplimiento, 'aspectos_administrativos' => $administrativos)); $user_info = get_userdata($user_id); $commentdata = array('comment_post_ID' => $post_id, 'comment_content' => $mensaje, 'comment_author' => $user_info->display_name, 'comment_type' => '', 'comment_parent' => 0, 'user_id' => $user_id); //Insert new comment and get the comment ID $comment_id = wp_new_comment($commentdata); $link = get_permalink($post_id); if ($result_insert == true) { $mensaje_ok = 'Guardando los datos, espere por favor'; echo json_encode(array('vote_ok' => true, 'redirect' => $link, 'message' => __($mensaje_ok))); die; } else { $mensaje_error = 'Ha habido un error en la votación, inténtelo mas tarde.'; echo json_encode(array('vote_ok' => false, 'message' => __($mensaje_error))); die; } }