<commit_before><?php
class ic extends CI_Controller {

	function __construct() {
		global $dd, $acao;
		parent::__construct();
		$this -> load -> library('form_validation');
		$this -> load -> database();
		$this -> lang -> load("app", "portuguese");
		$this -> lang -> load("ic", "portuguese");
		$this -> load -> library("nuSoap_lib");

		$this -> load -> helper('form');
		$this -> load -> helper('form_sisdoc');
		$this -> load -> helper('links_users');
		$this -> load -> helper('url');
		$this -> load -> helper('tcpdf');
		$this -> load -> library('session');

		date_default_timezone_set('America/Sao_Paulo');
		/* Security */
		$this -> security();
	}

	function security() {

		/* Seguranca */
		$this -> load -> model('usuarios');
		$this -> usuarios -> security();
	}

	function cab() {
		/* Carrega classes adicionais */
		$css = array();
		$js = array();
		array_push($css, 'style_cab.css');
		array_push($css, 'switch_onoff.css');
		array_push($css, 'form_sisdoc.css');
		array_push($js, 'js_cab.js');
		array_push($js, 'unslider.min.js');
		array_push($js, 'high/highcharts.js');

		/* transfere para variavel do codeigniter */
		$data['css'] = $css;
		$data['js'] = $js;

		/* Menu */
		$menus = array();
		array_push($menus, array('Home', 'index.php/ic/'));

		array_push($menus, array('Professores & Alunos', 'index.php/ic/usuarios'));
		array_push($menus, array('Avaliadores', 'index.php/ic/avaliadores'));
		array_push($menus, array('Acompanhamento', 'index.php/ic/acompanhamento'));
		array_push($menus, array('Pagamentos', 'index.php/ic/pagamentos'));
		array_push($menus, array('Relatrios', 'index.php/ic/report'));
		array_push($menus, array('Comunicao', 'index.php/ic/comunicacao/'));
		array_push($menus, array('Indicadores', 'index.php/ic/indicadores'));
		array_push($menus, array('Contratos', 'index.php/ic_contrato/contratos/'));
		array_push($menus, array('Administrativo', 'index.php/ic/admin/'));

		$data['menu'] = 1;
		$data['menus'] = $menus;

		/* Monta telas */
		$this -> load -> view('header/header', $data);
		$data['title_page'] = 'Iniciao Cientfica';
		$data['menu'] = 1;
		$this -> load -> view('header/cab', $data);

		$this -> load -> view('header/content_open');
		$data['logo'] = base_url('img/logo/logo_ic.png');
		$this -> load -> view('header/logo', $data);
	}


	function implementacao_manual() {
		$this -> load -> model('ics');
		$this -> load -> model('usuarios');
		$this -> cab();
		$tela = '';
		$title = '';

		$form = new form;
		if ((strlen(get("dd1")) != 7) or (strlen(get("dd2")) == 0)) {
			$cp = array();
			array_push($cp, array('$H8', '', '', False, True));
			array_push($cp, array('$S8', '', 'Informe o nmero do protocolo', True, True));
			$sql = "select * from ic_modalidade_bolsa where mb_vigente = 1 order by mb_descricao ";
			array_push($cp, array('$Q id_mb:mb_descricao:' . $sql, '', 'Modalidade de Bolsa', True, True));
			$tela = $form -> editar($cp, '');
		} else {
			/* */
			$tela = '';
			$proto = get("dd1");
			$chk1 = $this -> ics -> ja_implementado($proto);
			$chk2 = $this -> ics -> existe_projeto_enviado($proto);
			$chk3 = 0;
			$chk4 = 0;

			$data = date("Y-m-d");

			$cp = array();
			array_push($cp, array('$H8', '', '', False, True));
			array_push($cp, array('$S8', '', 'Informe o nmero do protocolo', True, True));
			$sql = "select * from ic_modalidade_bolsa where mb_vigente = 1 order by mb_descricao ";
			array_push($cp, array('$Q id_mb:mb_descricao:' . $sql, '', 'Modalidade de Bolsa', True, True));
			array_push($cp, array('$S8', '', 'Informe o cdigo do aluno', True, True));
			array_push($cp, array('$T80:3', '', '`Informe ttulo do plano', True, True));
			array_push($cp, array('$Q us_cracha:us_nome:select * from us_usuario where usuario_tipo_ust_id=2 and us_ativo = 1 order by us_nome ', '', 'Nome do orientador', True, True));
			array_push($cp, array('$D8', '', 'Incio da vigncia', True, True));
			array_push($cp, array('$[' . (date("Y") - 2) . '-' . date("Y") . ']', '', 'Ano do edital', True, True));
			$tela = $form -> editar($cp, '');

			if (($chk1 == 0) and ($chk2 == 0)) {
				$estudante = get("dd3");

				if ($form -> saved > 0) {
					$data_ativacao = brtod(get("dd6"));
					$prof = get("dd5");
					$hora = date("H:i:s");
					$proto = get("dd1");
					$ano = get("dd7");
					$titulo = get("dd4");
					$mdo = get("dd2");
					$ida = $this -> usuarios -> le_cracha($estudante);
					if ($ida == 0) {
						$aluno = $this -> usuarios -> consulta_cracha($estudante);
						$ida = $this -> usuarios -> le_cracha($estudante);
					}

					if (count($ida) > 0) {
						$aluno = $ida['id_us'];
						$aluno_cracha = $ida['us_cracha'];

						$chk3 = $this -> ics -> estudante_com_ic_implementado($aluno);

						if ($chk3 == 0) {
							$sql = "insert into ic
								(
									ic_cracha_prof, ic_cracha_aluno, s_id,
									s_id_char, ic_dt_ativacao, 
									ic_data, ic_hora, ic_ano,
									
									ic_projeto_professor_codigo, ic_projeto_professor_titulo, ic_plano_aluno_codigo,
									ic_plano_aluno_nome										
								) values (
									'$prof','$estudante','1',
									'A','$data_ativacao',
									'$data','$hora','$ano',
									
									'$proto','$titulo','$proto'
									,'$titulo'
								)";
							$this -> db -> query($sql);
							$idr = $this -> ics -> recupera_nr_ic($proto);
							if (count($idr) > 0) {
								$idp = $idr['id_ic'];
								$sql = "insert into ic_aluno
										(aluno_id, ic_aluno_cracha, ic_id,
										mb_id, 	icas_id, aic_dt_entrada, 
										aic_dt_inicio_bolsa
										) values (
										$aluno,'$aluno_cracha', $idp,
										$mdo, 1, '$data_ativacao',
										'$data_ativacao'
										)";
								$rlt = $this -> db -> query($sql);
								$this -> load -> view('sucesso');
								return ('');
							}
						}
					} else { $chk4 = 1;
					}
				}
			}

			$tela .= '<table>';
			$tela .= '<tr><td align="right">J implementado:</td><td><b>' . sn($chk1) . '</b></td></tr>';
			$tela .= '<tr><td align="right">Foi enviado cadastrado plano do aluno:</td><td><b>' . sn($chk2) . '</b></td></tr>';
			$tela .= '<tr><td align="right">Estudante j est na IC:</td><td><b>' . sn($chk3) . '</b></td></tr>';
			$tela .= '<tr><td align="right">Problema no cadastro do aluno:</td><td><b>' . sn($chk4) . '</b></td></tr>';

			$tela .= '</table>';
		}
		$data = array();
		$data['content'] = $tela;
		$data['title'] = 'Implementao manual';
		$this -> load -> view('content', $data);

	}

	function avaliadores_set() {
		/* Load Models */
		$this -> load -> model('avaliadores');
		$this -> avaliadores -> regra_avaliadores();
		redirect(base_url('index.php/ic'));
	}


	function pagamento_cracha($cracha = '', $chk = '') {
		$this -> load -> model('ics');
		$data['content'] = $this -> ics -> pagamentos_ic($cracha);
		$this -> load -> view('content', $data);
	}

	function comunicacao_edit($id = 0, $gr = 0, $tp = 0) {
		/* Load Models */
		$this -> load -> model('comunicacoes');
		$cp = $this -> comunicacoes -> cp();

		$this -> cab();
		$data = array();

		$form = new form;
		$form -> id = $id;

		$tela = $form -> editar($cp, $this -> comunicacoes -> tabela);
		$data['title'] = msg('eq_equipamento_title');
		$data['tela'] = $tela;
		$this -> load -> view('form/form', $data);

		/* Salva */
		if ($form -> saved > 0) {
			redirect(base_url('index.php/ic/comunicacao'));
		}

		//$this -> load -> view('content', $data);

		$this -> load -> view('header/content_close');
		$this -> load -> view('header/foot', $data);
	}

	function comunicacao_view($id = 0, $gr = 0, $tp = 0) {
		/* Load Models */
		$this -> load -> model('comunicacoes');

		$config = Array('protocol' => 'smtp', 'smtp_host' => 'smtps.pucpr.br', 'smtp_port' => 25, 'smtp_user' => '', 'smtp_pass' => '', 'mailtype' => 'html', 'charset' => 'iso-8859-1', 'wordwrap' => TRUE);
		$this -> load -> library('email', $config);

		$this -> cab();
		$data = array();

		$data = $this -> comunicacoes -> le($id);

		if (strlen(get("dd1")) == 0) {
			$id_gr = $data['mc_tipo'];
			$_POST['dd1'] = $this -> comunicacoes -> le_email_grupo($id_gr);
		}

		$head = base_url($data['m_header']);
		$foot = base_url($data['m_foot']);

		$msg_body = $data['mc_texto'];
		if ($data['mc_formato'] == 'TEXT') { $msg_body = mst($msg_body);
		}

		$form = new form;
		$cp = array();
		array_push($cp, array('$h', '', '', False, False));
		array_push($cp, array('$T40:50', '', 'emails', True, False));
		array_push($cp, array('$B8', '', 'Enviar >>>', False, False));
		$tela = $form -> editar($cp, '');
		$data['title'] = msg('visualizar_mensagem');
		$data['tela'] = $tela;

		if ($form -> saved > 0) {
			$em = get('dd1');
			$em = troca($em, chr(13), ';');
			$em = troca($em, chr(10), '');
			$em = troca($em, chr(8), '');
			$em = troca($em, chr(15), '');
			$ems = splitx(';', $em . ';');

			for ($r = 0; $r < count($ems); $r++) {
				$para = array($ems[$r]);
				$de = $data['mc_own'];
				$assunto = $data['mc_titulo'];

				/* texto */
				$texto_o = $data['mc_texto'];
				if (trim($data['mc_formato']) == 'TEXT') { $texto_o = mst($texto_o);
				}
				$texto = '<table width="700">';
				if (strlen($head) > 0) {
					$texto .= '<tr><td><img src="' . $head . '" width="700"></td></tr>';
					$texto .= '<tr><td><br></td></tr>';
				}
				$texto .= '<tr><td>';
				$texto .= $texto_o . '<br><br></td></tr>';

				if (strlen($foot) > 0) {
					$texto .= '<tr><td><img src="' . $foot . '" width="700"></td></tr>';
				}
				$texto .= '</table>';

				/* enviar e-mail */
				enviaremail($para, $assunto, $texto, $de);
			}
			enviaremail(array('cleybe.vie<EMAIL>'), $assunto, $texto, $de);
			enviaremail(array('<EMAIL>'), $assunto, $texto, $de);
		}

		$data['content'] = '<table width="100%">
							
							<tr valign="top">
								<td>
								<table width="700" align="center" class="border1">
								<tr><td><img src="' . $head . '" width="700"></td></tr>
								<tr><td><br>' . $msg_body . '</td></tr>
								<tr><td><br><br><br></td></tr>
								<tr><td><img src="' . $foot . '" width="700"></td></tr>									
								</table>
								</td>
								<td>' . $tela . '</td>
							</tr>
							
							</table>';

		$data['title'] = msg('visualizar_mensagem');

		$this -> load -> view('content', $data);

		$this -> load -> view('header/content_close');
		$this -> load -> view('header/foot', $data);
	}

	/*************************************************************************************************
	 *************************************************************************** SUBMISSAO MASTER ****
	 *************************************************************************************************/
	function submit_new() {
		$this -> load -> model('ics_master');
		$cracha = $_SESSION['cracha'];
		$this -> ics_master -> projeto_novo($cracha);
	}

	function submit_finished() {
		$this -> load -> model('ics');
		$this -> load -> model('ics_master');
		$this -> load -> model('geds');

		$this -> cab();
		$data = array();

		$data['content'] = '<center><h1><font color="green"><b>Submisso concluda com Sucesso!</b></font></h1></center>';
		$this -> load -> view('content', $data);
	}

	function submit_view() {
		$this -> load -> model('ics');
		$this -> load -> model('ics_master');
		$this -> load -> model('geds');

		$this -> cab();
		$data = array();

		$data['content'] = '<center><h1><font color="green"><b>Submisso concluda com Sucesso!</b></font></h1></center>';
		$this -> load -> view('content', $data);
	}

	function submit_edit($tipo = '', $id = '', $chk = '', $pag = '') {
		$this -> load -> model('ics');
		$this -> load -> model('ics_master');
		$this -> load -> model('geds');

		$this -> cab();
		$data = array();

		$prj_data = $this -> ics_master -> le($id);
		$sta = $prj_data['pj_status'];
		if ($sta != '@') {
			redirect(base_url('index.php/ic/submit_view/' . $id . '/' . checkpost_link($id)));
			exit ;
		}

		$bp = array();
		if (strlen($pag) == 0) { $pag = 1;
		}
		$data['bp_atual'] = $pag;

		switch ($tipo) {
			case 'ICMST' :
				$bp[1] = 'Identificao do projeto';
				$bp[2] = 'Submisso de Arquivos';
				$bp[3] = 'Confirmao';
				$data['bp'] = $bp;
				$data['bp_link'] = base_url('index.php/ic/submit_edit/' . $tipo . '/' . $id . '/' . $chk . '/');
				$this -> load -> view('gadget/progessbar_horizontal.php', $data);

				$form = new form;
				$form -> id = $id;

				switch ($pag) {
					case '1' :
						$cp = $this -> ics_master -> cp_subm_01();

						$tela = $form -> editar($cp, 'ic_submissao_projetos');

						$data['content'] = $tela;
						$this -> load -> view('content', $data);
						break;
					case '2' :
						$cp = $this -> ics_master -> cp_subm_02($id);
						$tela = $form -> editar($cp, 'ic_submissao_projetos');

						$data['content'] = $tela;
						$this -> load -> view('content', $data);
						break;
					case '3' :
						$cp = $this -> ics_master -> valida_entrada($id);

						$tela = $form -> editar($cp, 'ic_submissao_projetos');

						$data['content'] = $tela;
						$this -> load -> view('content', $data);
						break;
					case '4' :
						$this -> ics_master -> altera_status($id, 'A');
						redirect(base_url('index.php/ic/submit_finished/' . $id));
						break;
				}

				if ($form -> saved > 0) {
					redirect(base_url('index.php/ic/submit_edit/ICMST/' . $id . '/' . $chk . '/' . ($pag + 1)));
				}
		}

	}

	function submit_ICMST() {
		$this -> load -> model('ics_master');
		$this -> cab();

		$id_us = $_SESSION['id_us'];
		$cracha = $_SESSION['cracha'];
		$ano = date("Y");
		$tela = $this -> ics_master -> resumo_submit($cracha, $ano);

		/* Habilita boto de submisso */
		$prj = $this -> ics_master -> exist_submit($cracha, $ano);
		/* se 0, no existe projeto cadastrado */
		if ($prj > 0) {
			$chk = checkpost_link($prj);
			$tipo = 'ICMST';
			$botao = base_url('index.php/ic/submit_edit/' . $tipo . '/' . $prj . '/' . $chk . '/');
			$botao = '<a href="' . $botao . '" class="botao3d back_green_shadown back_green">';
			$botao .= msg('ic_submit_edit_project');
			$botao .= '</a>';
		} else {
			$botao = '<a href="' . base_url('index.php/ic/submit_new/ICMST') . '" class="botao3d back_green_shadown back_green">';
			$botao .= msg('ic_submit_new_project');
			$botao .= '</a>';
		}
		$tela .= '<br>' . $botao;

		$data['content'] = $tela;
		$this -> load -> view('content', $data);

	}

	function admin_rpar() {
		$this -> cab();
		$this -> load -> model("geds");
		$this -> geds -> tabela = 'ic_ged_documento';

		$d1 = '20160311';
		$d2 = '20160314';

		$sql = "select * from ic_ged_documento where doc_data >= $d1 and doc_data <= $d2 ";
		$sql .= " and doc_tipo = 'PRP' ";
		$rlt = $this -> db -> query($sql);
		$rlt = $rlt -> result_array();
		$sx = '<table width="100%" class="tabela00 lt3">';
		$http = 'https://cip.pucpr.br/';

		for ($r = 0; $r < count($rlt); $r++) {
			$line = $rlt[$r];
			$sx .= '<tr class="lt4">';
			$sx .= '<td>';
			$sx .= $line['doc_dd0'];
			$sx .= '</td>';
			$sx .= '<td>';
			$sx .= '<a href="' . $http . $line['doc_arquivo'] . '" target="new">' . $line['doc_filename'] . '</a>';
			$sx .= '</td>';
			$sx .= '<td>';
			$sx .= $line['doc_tipo'];
			$sx .= '</td>';
			$sx .= '<td>';
			$sx .= stodbr($line['doc_data']);
			$sx .= ' ';
			$sx .= substr($line['doc_hora'], 0, 5);
			$sx .= '</td>';
			$sx .= '<td>';
			$sx .= '<a href="' . base_url('index.php/ic/gera_novo_parecer/' . $line['id_doc']) . '" target="new">gerar novo</a>';
			$sx .= '</td>';

			$sx .= '</tr>';
		}
		print_r($line);
		$sx .= '</table>';
		$data['content'] = $sx;
		$this -> load -> view("content", $data);
	}

	function gera_novo_parecer($id) {
		$this->load->model("ics");
		$this->load->model("ic_pareceres");
		
		$sql = "select * from ic_ged_documento where id_doc = " . $id;
		$rlt = $this -> db -> query($sql);
		$rlt = $rlt -> result_array();

		if (count($rlt) > 0) {
			$line = $rlt[0];
			$proto = $line['doc_dd0'];
			
			$sql = "select * from pibic_parecer_".date("Y")." 
					where pp_protocolo = '$proto' 
						and pp_tipo = 'RPAR' 
						and pp_status = 'B' ";
			$rrlt = $this->db->query($sql);
			$rrlt = $rrlt->result_array();
			$dados = $rrlt[0];
			$dados2 = $this->ics->le_protocolo($proto);
			
			$dados3 = $this -> ic_pareceres -> le($id);
			$dados = array_merge($dados, $dados2,$dados3,$line);
			$nota = $dados['pp_p09'];
			$proto = $dados['pp_protocolo'];
			$this -> ic_pareceres -> finaliza_nota_ic($proto, $nota);

			$aluno = $this -> usuarios -> le_cracha($dados['ic_cracha_aluno']);

			/* gera PDF */
			$file_local = $this -> ic_pareceres -> gera_parecer('RPARC', $dados);

			for ($r=0;$r < 9999;$r++)
				{
					$file1 = $dados['doc_arquivo'];
					$file2 = $dados['doc_arquivo'].'-'.$r;
					echo '<br>'.$file2.' - ';
					if (!(file_exists($file2)))
						{
							$r = 9999;
							echo 'ok';
						}
						
				}
			if (file_exists($file1))
				{
					echo '->'.$file1.' - renomeado';
					rename($file1,$file2);
				} else {
					echo ' - arquivo no localizado!';
				}
			rename($file_local,$file1);

		}

	}

	/*************************************************************************************************
	 *************************************************************************** ADMINISTRATIVO ******
	 *************************************************************************************************/
	function admin($id = 0, $gr = '') {
		$this -> cab();
		$data = array();

		/* Menu de botes na tela Admin*/
		$menu = array();
		array_push($menu, array('Gesto', 'Alterar ttulo de plano de aluno', 'ITE', '/ic/admin_alterar_titulo'));
		array_push($menu, array('Gesto', 'Cancelar plano de estudante', 'ITE', '/ic/admin_cancelar'));
		array_push($menu, array('Gesto', 'Reativar plano cancelado', 'ITE', '/ic/admin_reativar'));
		array_push($menu, array('Gesto', 'Substituio de orientador', 'ITE', '/ic/admin_substituir_orientador'));
		array_push($menu, array('Gesto', 'Substituio de bolsa', 'ITE', '/ic/admin_substituir_bolsa'));

		array_push($menu, array('Entregas', 'Formulrio de acompanhamento', 'ITE', '/ic/acompanhamento'));

		array_push($menu, array('Implementao', 'Implementao Manual', 'ITE', '/ic/implementacao_manual'));

		array_push($menu, array('Discentes (seguro) ', 'Relatrio de discentes ativos IC Capital (Seguro)', 'ITE', '/ic/seguro/1'));
		array_push($menu, array('Discentes (seguro) ', 'Relatrio de discentes ativos IC Interior (Seguro)', 'ITE', '/ic/seguro/2'));

		array_push($menu, array('Relatrio Parcial ', 'Problemas no PDF do relatrio parcial', 'ITE', '/ic/admin_rpar'));

		/*View principal*/
		$data['menu'] = $menu;
		$data['title_menu'] = 'Menu Administrao';
		$this -> load -> view('header/main_menu', $data);

		/*Fecha */	/*Gera rodap*/
		$this -> load -> view('header/content_close');
		$this -> load -> view('header/foot', $data);
	}<commit_msg>#at.15.03.2016.a<commit_after><?php
class ic extends CI_Controller {

	function __construct() {
		global $dd, $acao;
		parent::__construct();
		$this -> load -> library('form_validation');
		$this -> load -> database();
		$this -> lang -> load("app", "portuguese");
		$this -> lang -> load("ic", "portuguese");
		$this -> load -> library("nuSoap_lib");

		$this -> load -> helper('form');
		$this -> load -> helper('form_sisdoc');
		$this -> load -> helper('links_users');
		$this -> load -> helper('url');
		$this -> load -> helper('tcpdf');
		$this -> load -> library('session');

		date_default_timezone_set('America/Sao_Paulo');
		/* Security */
		$this -> security();
	}

	function security() {

		/* Seguranca */
		$this -> load -> model('usuarios');
		$this -> usuarios -> security();
	}

	function cab() {
		/* Carrega classes adicionais */
		$css = array();
		$js = array();
		array_push($css, 'style_cab.css');
		array_push($css, 'switch_onoff.css');
		array_push($css, 'form_sisdoc.css');
		array_push($js, 'js_cab.js');
		array_push($js, 'unslider.min.js');
		array_push($js, 'high/highcharts.js');

		/* transfere para variavel do codeigniter */
		$data['css'] = $css;
		$data['js'] = $js;

		/* Menu */
		$menus = array();
		array_push($menus, array('Home', 'index.php/ic/'));

		array_push($menus, array('Professores & Alunos', 'index.php/ic/usuarios'));
		array_push($menus, array('Avaliadores', 'index.php/ic/avaliadores'));
		array_push($menus, array('Acompanhamento', 'index.php/ic/acompanhamento'));
		array_push($menus, array('Pagamentos', 'index.php/ic/pagamentos'));
		array_push($menus, array('Relatrios', 'index.php/ic/report'));
		array_push($menus, array('Comunicao', 'index.php/ic/comunicacao/'));
		array_push($menus, array('Indicadores', 'index.php/ic/indicadores'));
		array_push($menus, array('Contratos', 'index.php/ic_contrato/contratos/'));
		array_push($menus, array('Administrativo', 'index.php/ic/admin/'));

		$data['menu'] = 1;
		$data['menus'] = $menus;

		/* Monta telas */
		$this -> load -> view('header/header', $data);
		$data['title_page'] = 'Iniciao Cientfica';
		$data['menu'] = 1;
		$this -> load -> view('header/cab', $data);

		$this -> load -> view('header/content_open');
		$data['logo'] = base_url('img/logo/logo_ic.png');
		$this -> load -> view('header/logo', $data);
	}


	function implementacao_manual() {
		$this -> load -> model('ics');
		$this -> load -> model('usuarios');
		$this -> cab();
		$tela = '';
		$title = '';

		$form = new form;
		if ((strlen(get("dd1")) != 7) or (strlen(get("dd2")) == 0)) {
			$cp = array();
			array_push($cp, array('$H8', '', '', False, True));
			array_push($cp, array('$S8', '', 'Informe o nmero do protocolo', True, True));
			$sql = "select * from ic_modalidade_bolsa where mb_vigente = 1 order by mb_descricao ";
			array_push($cp, array('$Q id_mb:mb_descricao:' . $sql, '', 'Modalidade de Bolsa', True, True));
			$tela = $form -> editar($cp, '');
		} else {
			/* */
			$tela = '';
			$proto = get("dd1");
			$chk1 = $this -> ics -> ja_implementado($proto);
			$chk2 = $this -> ics -> existe_projeto_enviado($proto);
			$chk3 = 0;
			$chk4 = 0;

			$data = date("Y-m-d");

			$cp = array();
			array_push($cp, array('$H8', '', '', False, True));
			array_push($cp, array('$S8', '', 'Informe o nmero do protocolo', True, True));
			$sql = "select * from ic_modalidade_bolsa where mb_vigente = 1 order by mb_descricao ";
			array_push($cp, array('$Q id_mb:mb_descricao:' . $sql, '', 'Modalidade de Bolsa', True, True));
			array_push($cp, array('$S8', '', 'Informe o cdigo do aluno', True, True));
			array_push($cp, array('$T80:3', '', '`Informe ttulo do plano', True, True));
			array_push($cp, array('$Q us_cracha:us_nome:select * from us_usuario where usuario_tipo_ust_id=2 and us_ativo = 1 order by us_nome ', '', 'Nome do orientador', True, True));
			array_push($cp, array('$D8', '', 'Incio da vigncia', True, True));
			array_push($cp, array('$[' . (date("Y") - 2) . '-' . date("Y") . ']', '', 'Ano do edital', True, True));
			$tela = $form -> editar($cp, '');

			if (($chk1 == 0) and ($chk2 == 0)) {
				$estudante = get("dd3");

				if ($form -> saved > 0) {
					$data_ativacao = brtod(get("dd6"));
					$prof = get("dd5");
					$hora = date("H:i:s");
					$proto = get("dd1");
					$ano = get("dd7");
					$titulo = get("dd4");
					$mdo = get("dd2");
					$ida = $this -> usuarios -> le_cracha($estudante);
					if ($ida == 0) {
						$aluno = $this -> usuarios -> consulta_cracha($estudante);
						$ida = $this -> usuarios -> le_cracha($estudante);
					}

					if (count($ida) > 0) {
						$aluno = $ida['id_us'];
						$aluno_cracha = $ida['us_cracha'];

						$chk3 = $this -> ics -> estudante_com_ic_implementado($aluno);

						if ($chk3 == 0) {
							$sql = "insert into ic
								(
									ic_cracha_prof, ic_cracha_aluno, s_id,
									s_id_char, ic_dt_ativacao, 
									ic_data, ic_hora, ic_ano,
									
									ic_projeto_professor_codigo, ic_projeto_professor_titulo, ic_plano_aluno_codigo,
									ic_plano_aluno_nome										
								) values (
									'$prof','$estudante','1',
									'A','$data_ativacao',
									'$data','$hora','$ano',
									
									'$proto','$titulo','$proto'
									,'$titulo'
								)";
							$this -> db -> query($sql);
							$idr = $this -> ics -> recupera_nr_ic($proto);
							if (count($idr) > 0) {
								$idp = $idr['id_ic'];
								$sql = "insert into ic_aluno
										(aluno_id, ic_aluno_cracha, ic_id,
										mb_id, 	icas_id, aic_dt_entrada, 
										aic_dt_inicio_bolsa
										) values (
										$aluno,'$aluno_cracha', $idp,
										$mdo, 1, '$data_ativacao',
										'$data_ativacao'
										)";
								$rlt = $this -> db -> query($sql);
								$this -> load -> view('sucesso');
								return ('');
							}
						}
					} else { $chk4 = 1;
					}
				}
			}

			$tela .= '<table>';
			$tela .= '<tr><td align="right">J implementado:</td><td><b>' . sn($chk1) . '</b></td></tr>';
			$tela .= '<tr><td align="right">Foi enviado cadastrado plano do aluno:</td><td><b>' . sn($chk2) . '</b></td></tr>';
			$tela .= '<tr><td align="right">Estudante j est na IC:</td><td><b>' . sn($chk3) . '</b></td></tr>';
			$tela .= '<tr><td align="right">Problema no cadastro do aluno:</td><td><b>' . sn($chk4) . '</b></td></tr>';

			$tela .= '</table>';
		}
		$data = array();
		$data['content'] = $tela;
		$data['title'] = 'Implementao manual';
		$this -> load -> view('content', $data);

	}

	function avaliadores_set() {
		/* Load Models */
		$this -> load -> model('avaliadores');
		$this -> avaliadores -> regra_avaliadores();
		redirect(base_url('index.php/ic'));
	}


	function pagamento_cracha($cracha = '', $chk = '') {
		$this -> load -> model('ics');
		$data['content'] = $this -> ics -> pagamentos_ic($cracha);
		$this -> load -> view('content', $data);
	}

	function comunicacao_edit($id = 0, $gr = 0, $tp = 0) {
		/* Load Models */
		$this -> load -> model('comunicacoes');
		$cp = $this -> comunicacoes -> cp();

		$this -> cab();
		$data = array();

		$form = new form;
		$form -> id = $id;

		$tela = $form -> editar($cp, $this -> comunicacoes -> tabela);
		$data['title'] = msg('eq_equipamento_title');
		$data['tela'] = $tela;
		$this -> load -> view('form/form', $data);

		/* Salva */
		if ($form -> saved > 0) {
			redirect(base_url('index.php/ic/comunicacao'));
		}

		//$this -> load -> view('content', $data);

		$this -> load -> view('header/content_close');
		$this -> load -> view('header/foot', $data);
	}

	function comunicacao_view($id = 0, $gr = 0, $tp = 0) {
		/* Load Models */
		$this -> load -> model('comunicacoes');

		$config = Array('protocol' => 'smtp', 'smtp_host' => 'smtps.pucpr.br', 'smtp_port' => 25, 'smtp_user' => '', 'smtp_pass' => '', 'mailtype' => 'html', 'charset' => 'iso-8859-1', 'wordwrap' => TRUE);
		$this -> load -> library('email', $config);

		$this -> cab();
		$data = array();

		$data = $this -> comunicacoes -> le($id);

		if (strlen(get("dd1")) == 0) {
			$id_gr = $data['mc_tipo'];
			$_POST['dd1'] = $this -> comunicacoes -> le_email_grupo($id_gr);
		}

		$head = base_url($data['m_header']);
		$foot = base_url($data['m_foot']);

		$msg_body = $data['mc_texto'];
		if ($data['mc_formato'] == 'TEXT') { $msg_body = mst($msg_body);
		}

		$form = new form;
		$cp = array();
		array_push($cp, array('$h', '', '', False, False));
		array_push($cp, array('$T40:50', '', 'emails', True, False));
		array_push($cp, array('$B8', '', 'Enviar >>>', False, False));
		$tela = $form -> editar($cp, '');
		$data['title'] = msg('visualizar_mensagem');
		$data['tela'] = $tela;

		if ($form -> saved > 0) {
			$em = get('dd1');
			$em = troca($em, chr(13), ';');
			$em = troca($em, chr(10), '');
			$em = troca($em, chr(8), '');
			$em = troca($em, chr(15), '');
			$ems = splitx(';', $em . ';');

			for ($r = 0; $r < count($ems); $r++) {
				$para = array($ems[$r]);
				$de = $data['mc_own'];
				$assunto = $data['mc_titulo'];

				/* texto */
				$texto_o = $data['mc_texto'];
				if (trim($data['mc_formato']) == 'TEXT') { $texto_o = mst($texto_o);
				}
				$texto = '<table width="700">';
				if (strlen($head) > 0) {
					$texto .= '<tr><td><img src="' . $head . '" width="700"></td></tr>';
					$texto .= '<tr><td><br></td></tr>';
				}
				$texto .= '<tr><td>';
				$texto .= $texto_o . '<br><br></td></tr>';

				if (strlen($foot) > 0) {
					$texto .= '<tr><td><img src="' . $foot . '" width="700"></td></tr>';
				}
				$texto .= '</table>';

				/* enviar e-mail */
				enviaremail($para, $assunto, $texto, $de);
			}
			enviaremail(array('<EMAIL>'), $assunto, $texto, $de);
			enviaremail(array('<EMAIL>'), $assunto, $texto, $de);
		}

		$data['content'] = '<table width="100%">
							
							<tr valign="top">
								<td>
								<table width="700" align="center" class="border1">
								<tr><td><img src="' . $head . '" width="700"></td></tr>
								<tr><td><br>' . $msg_body . '</td></tr>
								<tr><td><br><br><br></td></tr>
								<tr><td><img src="' . $foot . '" width="700"></td></tr>									
								</table>
								</td>
								<td>' . $tela . '</td>
							</tr>
							
							</table>';

		$data['title'] = msg('visualizar_mensagem');

		$this -> load -> view('content', $data);

		$this -> load -> view('header/content_close');
		$this -> load -> view('header/foot', $data);
	}

	/*************************************************************************************************
	 *************************************************************************** SUBMISSAO MASTER ****
	 *************************************************************************************************/
	function submit_new() {
		$this -> load -> model('ics_master');
		$cracha = $_SESSION['cracha'];
		$this -> ics_master -> projeto_novo($cracha);
	}

	function submit_finished() {
		$this -> load -> model('ics');
		$this -> load -> model('ics_master');
		$this -> load -> model('geds');

		$this -> cab();
		$data = array();

		$data['content'] = '<center><h1><font color="green"><b>Submisso concluda com Sucesso!</b></font></h1></center>';
		$this -> load -> view('content', $data);
	}

	function submit_view() {
		$this -> load -> model('ics');
		$this -> load -> model('ics_master');
		$this -> load -> model('geds');

		$this -> cab();
		$data = array();

		$data['content'] = '<center><h1><font color="green"><b>Submisso concluda com Sucesso!</b></font></h1></center>';
		$this -> load -> view('content', $data);
	}

	function submit_edit($tipo = '', $id = '', $chk = '', $pag = '') {
		$this -> load -> model('ics');
		$this -> load -> model('ics_master');
		$this -> load -> model('geds');

		$this -> cab();
		$data = array();

		$prj_data = $this -> ics_master -> le($id);
		$sta = $prj_data['pj_status'];
		if ($sta != '@') {
			redirect(base_url('index.php/ic/submit_view/' . $id . '/' . checkpost_link($id)));
			exit ;
		}

		$bp = array();
		if (strlen($pag) == 0) { $pag = 1;
		}
		$data['bp_atual'] = $pag;

		switch ($tipo) {
			case 'ICMST' :
				$bp[1] = 'Identificao do projeto';
				$bp[2] = 'Submisso de Arquivos';
				$bp[3] = 'Confirmao';
				$data['bp'] = $bp;
				$data['bp_link'] = base_url('index.php/ic/submit_edit/' . $tipo . '/' . $id . '/' . $chk . '/');
				$this -> load -> view('gadget/progessbar_horizontal.php', $data);

				$form = new form;
				$form -> id = $id;

				switch ($pag) {
					case '1' :
						$cp = $this -> ics_master -> cp_subm_01();

						$tela = $form -> editar($cp, 'ic_submissao_projetos');

						$data['content'] = $tela;
						$this -> load -> view('content', $data);
						break;
					case '2' :
						$cp = $this -> ics_master -> cp_subm_02($id);
						$tela = $form -> editar($cp, 'ic_submissao_projetos');

						$data['content'] = $tela;
						$this -> load -> view('content', $data);
						break;
					case '3' :
						$cp = $this -> ics_master -> valida_entrada($id);

						$tela = $form -> editar($cp, 'ic_submissao_projetos');

						$data['content'] = $tela;
						$this -> load -> view('content', $data);
						break;
					case '4' :
						$this -> ics_master -> altera_status($id, 'A');
						redirect(base_url('index.php/ic/submit_finished/' . $id));
						break;
				}

				if ($form -> saved > 0) {
					redirect(base_url('index.php/ic/submit_edit/ICMST/' . $id . '/' . $chk . '/' . ($pag + 1)));
				}
		}

	}

	function submit_ICMST() {
		$this -> load -> model('ics_master');
		$this -> cab();

		$id_us = $_SESSION['id_us'];
		$cracha = $_SESSION['cracha'];
		$ano = date("Y");
		$tela = $this -> ics_master -> resumo_submit($cracha, $ano);

		/* Habilita boto de submisso */
		$prj = $this -> ics_master -> exist_submit($cracha, $ano);
		/* se 0, no existe projeto cadastrado */
		if ($prj > 0) {
			$chk = checkpost_link($prj);
			$tipo = 'ICMST';
			$botao = base_url('index.php/ic/submit_edit/' . $tipo . '/' . $prj . '/' . $chk . '/');
			$botao = '<a href="' . $botao . '" class="botao3d back_green_shadown back_green">';
			$botao .= msg('ic_submit_edit_project');
			$botao .= '</a>';
		} else {
			$botao = '<a href="' . base_url('index.php/ic/submit_new/ICMST') . '" class="botao3d back_green_shadown back_green">';
			$botao .= msg('ic_submit_new_project');
			$botao .= '</a>';
		}
		$tela .= '<br>' . $botao;

		$data['content'] = $tela;
		$this -> load -> view('content', $data);

	}
	
	
	function admin_rpar_lista_professores_com_erro_no_pdf() {
		$this -> cab();
		$this -> load -> model("geds");
		$this -> geds -> tabela = 'ic_ged_documento';
		$this -> load -> model('usuarios');
		$this -> load -> model('ics');
		
		
		$data['title'] = msg('Emails que deram erro no pdf do RP nos dias 11  14 de Maro de 2016');
		//$data['submenu'] = '<a href="'.base_url('index.php/ic/admin_rpar_lista_professores_com_erro_no_pdf').'" class="lt0 link">exportar para excel</a>';
	
		$d1 = '20160311';
		$d2 = '20160314';

		//$sql = "select * from ic_ged_documento where doc_data >= $d1 and doc_data <= $d2 ";
		$sql = "select distinct doc_dd0, ic_cracha_prof, us_nome, usm_email, 
                ic_plano_aluno_codigo, us_cracha,
                id_us, usuario_id_us, id_usm, usm_tipo, usm_ativo
						from ic_ged_documento
						left join ic on ic_plano_aluno_codigo = doc_dd0
						left join us_usuario on ic_cracha_prof = us_cracha
						inner join us_email on id_us = usuario_id_us
						where doc_data >= $d1 
						and doc_data <= $d2 
						and usm_ativo = 1
						group by doc_dd0, ic_cracha_prof, us_nome, usm_email, 
						         ic_plano_aluno_codigo, us_cracha,
						         id_us, usuario_id_us, id_usm, usm_tipo, usm_ativo
		
		";
		$sql .= " and doc_tipo = 'PRP' ";
		$rlt = $this -> db -> query($sql);
		$rlt = $rlt -> result_array();
		$sx = '<table width="100%" class="tabela00 lt3">';
		$http = 'https://cip.pucpr.br/';
	
		$sx .= '<tr><th align="left">#</th>
								<th align="left">Protocolo</th>
								<th align="left">Cracha</th>
								<th align="left">Professor</th>
								<th align="left">email</th>
								<th align="left">email_tipo</th>

						</tr>';	
		$tot = 0;
			
		for ($r = 0; $r < count($rlt); $r++) {
			$line = $rlt[$r];
			$tot++;
			$sx .= '<tr class="lt4">';
			
			//indice
			$sx .= '<td class="lt2">'.($r+1).'.</td>';
			
			$sx .= '<td class="lt2">';
			$sx .= $line['doc_dd0'];
			$sx .= '</td>';
			
			$sx .= '<td class="lt2">';
			$sx .= $line['ic_cracha_prof'];
			$sx .= '</td>';
			
			//nome_prof
			$sx .= '<td class="lt1">';
			$sx .= link_perfil($line['us_nome'], $line['id_us']);
			$sx .= '</td>';
			
			$sx .= '<td class="lt2">';
			$sx .= $line['usm_email'];
			$sx .= '</td>';
			
			$sx .= '<td class="lt2">';
			$sx .= $line['usm_tipo'];
			$sx .= '</td>';

			$sx .= '</tr>';
		}
		//print_r($line);
		$sx .= '</table>';
		
		$sx .= '<TR><TD colspan=6> '.$tot.' emails';
		$sx .= '</BR>';
		$sx .= '<TR><TD class="lt1"><font color="red"> obs.: Existem professores com mais de um emal cadasdtrado em seu perfil</font>';
		
		$data['content'] = $sx;
		

				$this -> load -> view("content", $data);
		
	}
	

	function admin_rpar() {
		$this -> cab();
		$this -> load -> model("geds");
		$this -> geds -> tabela = 'ic_ged_documento';

		$d1 = '20160311';
		$d2 = '20160314';

		$sql = "select * from ic_ged_documento where doc_data >= $d1 and doc_data <= $d2 ";
		$sql .= " and doc_tipo = 'PRP' ";
		$rlt = $this -> db -> query($sql);
		$rlt = $rlt -> result_array();
		$sx = '<table width="100%" class="tabela00 lt3">';
		$http = 'https://cip.pucpr.br/';

		for ($r = 0; $r < count($rlt); $r++) {
			$line = $rlt[$r];
			$sx .= '<tr class="lt4">';
			$sx .= '<td>';
			$sx .= $line['doc_dd0'];
			$sx .= '</td>';
			$sx .= '<td>';
			$sx .= '<a href="' . $http . $line['doc_arquivo'] . '" target="new">' . $line['doc_filename'] . '</a>';
			$sx .= '</td>';
			$sx .= '<td>';
			$sx .= $line['doc_tipo'];
			$sx .= '</td>';
			$sx .= '<td>';
			$sx .= stodbr($line['doc_data']);
			$sx .= ' ';
			$sx .= substr($line['doc_hora'], 0, 5);
			$sx .= '</td>';
			$sx .= '<td>';
			$sx .= '<a href="' . base_url('index.php/ic/gera_novo_parecer/' . $line['id_doc']) . '" target="new">gerar novo</a>';
			$sx .= '</td>';

			$sx .= '</tr>';
		}
		//print_r($line);
		$sx .= '</table>';
		$data['content'] = $sx;
		$this -> load -> view("content", $data);
	}

	function gera_novo_parecer($id) {
		$this->load->model("ics");
		$this->load->model("ic_pareceres");
		
		$sql = "select * from ic_ged_documento where id_doc = " . $id;
		$rlt = $this -> db -> query($sql);
		$rlt = $rlt -> result_array();

		if (count($rlt) > 0) {
			$line = $rlt[0];
			$proto = $line['doc_dd0'];
			
			$sql = "select * from pibic_parecer_".date("Y")." 
					where pp_protocolo = '$proto' 
						and pp_tipo = 'RPAR' 
						and pp_status = 'B' ";
			$rrlt = $this->db->query($sql);
			$rrlt = $rrlt->result_array();
			$dados = $rrlt[0];
			$dados2 = $this->ics->le_protocolo($proto);
			
			$dados3 = $this -> ic_pareceres -> le($id);
			$dados = array_merge($dados, $dados2,$dados3,$line);
			$nota = $dados['pp_p09'];
			$proto = $dados['pp_protocolo'];
			$this -> ic_pareceres -> finaliza_nota_ic($proto, $nota);

			$aluno = $this -> usuarios -> le_cracha($dados['ic_cracha_aluno']);

			/* gera PDF */
			$file_local = $this -> ic_pareceres -> gera_parecer('RPARC', $dados);

			for ($r=0;$r < 9999;$r++)
				{
					$file1 = $dados['doc_arquivo'];
					$file2 = $dados['doc_arquivo'].'-'.$r;
					echo '<br>'.$file2.' - ';
					if (!(file_exists($file2)))
						{
							$r = 9999;
							echo 'ok';
						}
						
				}
			if (file_exists($file1))
				{
					echo '->'.$file1.' - renomeado';
					rename($file1,$file2);
				} else {
					echo ' - arquivo no localizado!';
				}
			rename($file_local,$file1);

		}

	}

	/*************************************************************************************************
	 *************************************************************************** ADMINISTRATIVO ******
	 *************************************************************************************************/
	function admin($id = 0, $gr = '') {
		$this -> cab();
		$data = array();

		/* Menu de botes na tela Admin*/
		$menu = array();
		array_push($menu, array('Gesto', 'Alterar ttulo de plano de aluno', 'ITE', '/ic/admin_alterar_titulo'));
		array_push($menu, array('Gesto', 'Cancelar plano de estudante', 'ITE', '/ic/admin_cancelar'));
		array_push($menu, array('Gesto', 'Reativar plano cancelado', 'ITE', '/ic/admin_reativar'));
		array_push($menu, array('Gesto', 'Substituio de orientador', 'ITE', '/ic/admin_substituir_orientador'));
		array_push($menu, array('Gesto', 'Substituio de bolsa', 'ITE', '/ic/admin_substituir_bolsa'));

		array_push($menu, array('Entregas', 'Formulrio de acompanhamento', 'ITE', '/ic/acompanhamento'));

		array_push($menu, array('Implementao', 'Implementao Manual', 'ITE', '/ic/implementacao_manual'));

		array_push($menu, array('Discentes (seguro) ', 'Relatrio de discentes ativos IC Capital (Seguro)', 'ITE', '/ic/seguro/1'));
		array_push($menu, array('Discentes (seguro) ', 'Relatrio de discentes ativos IC Interior (Seguro)', 'ITE', '/ic/seguro/2'));

		array_push($menu, array('Relatrio Parcial ', 'Problemas no PDF do relatrio parcial', 'ITE', '/ic/admin_rpar'));
		array_push($menu, array('Relatrio Parcial ', 'Professores com problemas no PDF do RP', 'ITE', '/ic/admin_rpar_lista_professores_com_erro_no_pdf'));

		/*View principal*/
		$data['menu'] = $menu;
		$data['title_menu'] = 'Menu Administrao';
		$this -> load -> view('header/main_menu', $data);

		/*Fecha */	/*Gera rodap*/
		$this -> load -> view('header/content_close');
		$this -> load -> view('header/foot', $data);
	}
{'fraction_non_alphanumeric': 0.26057955977173347, 'fraction_numerical': 0.011116875416882829, 'mean_word_length': 3.169756901524516, 'pattern_counts': {'":': 0, '<': 317, '<?xml version=': 0, '>': 782, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2860770', 'n_tokens_mistral': 18540, 'n_tokens_neox': 15467, 'n_words': 3024}