<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Images extends Admin_Controller {
    
    private $tables; 
    
	function __construct()
	{
		parent::__construct();
		
		$this->tables = 
		[
		    1 => [
                'cad_proposta' => [
                    'logo'
                ]
            ],
            2 => [
                'blg_postagem' => [
                    'img'
                ]
            ],
            3 => [
                'cad_cadastro' => [
                    'img_perfil_uri',
                    'img_pj_uri',
                    'depoimento_file',
                    'depoimento_video'
                ]
            ],
            4 => [
                'cad_img' => [
                    'uri'
                ]
            ],
            5 => [
                'cad_imovel' => [
                    'contrato_prestacao',
                    'dn_img_uri',
                    'dn_img',
                    'doc_propriedade',
                    'doc_planilha'
                ]
            ],
            6 => [
                'fnc_banco_rel_simulacao' => [
                    'file_url'
                ],
                'inc_empreendimento' => [
                    'emp_logo',
                    'res_foto'
                ],
                'inc_evento' => [
                    'logo1',
                    'logo2',
                    'video',
                    'seo_img'
                ],
                'inc_incorporadora' => [
                    'logo'
                ],
                'inc_investimento_midias' => [
                    'comprovante'
                ],
                'inc_parceiro' => [
                    'par_logo'
                ],
                'lp_comodidades' => [
                    'img_url'
                ],
                'lp_config' => [
                    'bg_topo_video',
                    'img_lp',
                    'img_mobile',
                    'pagina_logo',
                    'pagina_at_video',
                    'pagina_at_ebook_file',
                    'pagina_at_ebook_img',
                    'pagina_ag_capa',
                    'seo_img',
                    'video',
                    'form_imagem'
                ],
                'lp_unidades' => [
                    'img',
                    'img_url'
                ],
                'cad_interesse' => [
                    'avatar'
                ]
            ],
            7 => [
                'nwl_campanha_email' => [
                    'mensagem'
                ]
            ],
            8 => [
                'fnc_simulacao' => [
                    'historico_email'
                ]
            ],
        ];
        
		$this->load->model('cad_model');
	}
	
	public function index($page=null){
        
        if((int)$page > 0 ){
            
            $tables = $this->tables[$page];
            
            // DEVELOPMENT - inline
            /*$bases = [
                'https:\/\/s3.us-west-2.amazonaws.com\/dev.comdono\/'
            ];
            
            $baseNew = 'https:\/\/dev-comdono.sfo3.cdn.digitaloceanspaces.com\/';*/
            
            // DEVELOPMENT
            /*$bases = [
                'https://s3.us-west-2.amazonaws.com/dev.comdono'
            ];*/
            
            // PRODUCTION
            $bases = [
                'https://comdono.s3.us-west-2.amazonaws.com',
                'https://comdono.s3-us-west-2.amazonaws.com',
                'https://s3.us-west-2.amazonaws.com/comdono',
                'https://images.comdono.com'
            ];
            
            $baseNew = getenv('MEDIA_URL');
            
            foreach ($bases as $base)
            {
                foreach ($tables as $tb=>$cols)
                {
                    $tables[$tb]['getResult'] = $this->cad_model->getResult($tb);
                    
                    $tables[$tb]['pk'] = $this->cad_model->getPrimaryKey($tb);
                    
                    foreach ($tables[$tb]['getResult'] as $row){
                        
                        foreach ($cols as $col){
                            if(is_array($col))
                                continue;
                            $pos = strpos($row->$col,$base);
                            if($pos !== false) {
                                
                                $data = [];
                                $data[$col] = str_replace($base,$baseNew,$row->$col);
                                
                                $pk = $tables[$tb]['pk'];
                                $this->db->where($pk,$row->$pk);
                                $this->cad_model->update($tb,$data);
                                
                                /*var_dump($pk,$tb,$data);
                                die();*/
                                
                            }else{
                                //dd($pos);
                            }
                        }
                    }
                } 
            }
            
            e('sextô');
        }
    }
    
    public function str(){
        $str = '
            <center>
<table align="center" border="0" cellpadding="0" cellspacing="0" height="100%" id="m_6355739659377522657bodyTable" width="100%">
	<tbody>
		<tr>
			<td align="center" id="m_6355739659377522657bodyCell" valign="top">
			<table border="0" cellpadding="0" cellspacing="0" width="100%">
				<tbody>
					<tr>
						<td align="center" id="m_6355739659377522657templateHeader" valign="top">
						<table align="center" border="0" cellpadding="0" cellspacing="0" width="100%">
							<tbody>
								<tr>
									<td valign="top">
									<table border="0" cellpadding="0" cellspacing="0" style="min-width:100%" width="100%">
										<tbody>
											<tr>
												<td style="padding:0px" valign="top">
												<table align="left" border="0" cellpadding="0" cellspacing="0" style="min-width:600px;background: #253054;padding: 50px 0;" width="100%">
													<tbody>
														<tr>
															<td style="padding-right:0px;padding-left:0px;padding-top:0;padding-bottom:0;text-align:center" valign="top"><img align="middle" alt="" class="CToWUd a6T" src="https://ci4.googleusercontent.com/proxy/0j--D8hkfssvdPN6LvvAmQaZbwYacCkgKk6GQzdAfXNkx0rsm2XtQ-zUyyikgM1io1OURQygrH5jo0qqGPXIbuSqz-L5d8y-rWcJQWf3T8cdZS0JO1qkbtqB9HuWCmZ_gNG0Pm9fh-QhWJvL4LbCB5_1OMZXDA=s0-d-e1-ft#https://mcusercontent.com/b8d28a34811d3b7746fbf94e7/images/ef228f78-c4b0-4ca6-a99c-c2ef567f2298.png" style="max-width:1083px;padding-bottom:0;display:inline!important;vertical-align:bottom" tabindex="0" width="162" />
															<div class="a6S" dir="ltr" style="opacity: 0.01; left: 785px; top: 111px;">
															<div aria-label="Fazer o download do anexo " class="T-I J-J5-Ji aQv T-I-ax7 L3 a5q" data-tooltip="Fazer o download" data-tooltip-class="a1V" id=":1kr" role="button" tabindex="0">
															<div class="wkMEBb">
															<div class="aSK J-J5-Ji aYr">&nbsp;</div>
															</div>
															</div>
															</div>
															</td>
														</tr>
													</tbody>
												</table>
												</td>
											</tr>
										</tbody>
									</table>
									</td>
								</tr>
							</tbody>
						</table>
						</td>
					</tr>
					<tr>
						<td align="center" id="m_6355739659377522657templateBody" valign="top">
						<table align="center" border="0" cellpadding="0" cellspacing="0" style="
    width: 600px;
" width="100%">
							<tbody>
								<tr>
									<td valign="top">
									<table border="0" cellpadding="0" cellspacing="0" style="min-width:100%" width="100%">
										<tbody>
											<tr>
												<td style="padding-top:9px" valign="top">
												<table align="left" border="0" cellpadding="0" cellspacing="0" style="max-width:100%;min-width:100%" width="100%">
													<tbody>
														<tr>
															<td style="padding:0px 18px 9px;text-align:left" valign="top">
															<h1 style="text-align:center"><span style="color:#253054"><strong><span style="font-size:32px">Confirmamos o agendamento da reunião virtual!</span></strong></span></h1>
															</td>
														</tr>
													</tbody>
												</table>
												</td>
											</tr>
										</tbody>
									</table>

									<table border="0" cellpadding="0" cellspacing="0" style="min-width:100%;width: 600px;" width="100%">
										<tbody>
											<tr>
												<td style="padding:0px" valign="top">
												<table align="left" border="0" cellpadding="0" cellspacing="0" style="min-width:100%" width="100%">
													<tbody>
														<tr>
															<td style="padding-right:0px;padding-left:0px;padding-top:0;padding-bottom:0;text-align:center" valign="top"><img align="middle" alt="" class="CToWUd a6T" src="https://ci4.googleusercontent.com/proxy/cw1Txcmy1Zw84MM1eiNoeSGiZ8RprfgSwldFOdm9T4ILJlNMpWTDXjOmRAGdmzhp-ls_s_BzgXFFlfyQZzSDHPsM8ABqin88oa64oZc3H6C7T71LgWkN2_HbA_GVScaLvtVyoC8bNtfSlL4sRx21ZFsbTbCdEw=s0-d-e1-ft#https://mcusercontent.com/b8d28a34811d3b7746fbf94e7/images/6756012b-0652-4134-9981-387786a86ccf.jpg" style="max-width:1200px;padding-bottom:0;display:inline!important;vertical-align:bottom" tabindex="0" width="600" />
															<div class="a6S" dir="ltr" style="opacity: 0.01; left: 1004px; top: 599px;">
															<div aria-label="Fazer o download do anexo " class="T-I J-J5-Ji aQv T-I-ax7 L3 a5q" data-tooltip="Fazer o download" data-tooltip-class="a1V" id=":1ks" role="button" tabindex="0">
															<div class="wkMEBb">
															<div class="aSK J-J5-Ji aYr">&nbsp;</div>
															</div>
															</div>
															</div>
															</td>
														</tr>
													</tbody>
												</table>
												</td>
											</tr>
										</tbody>
									</table>

									<table border="0" cellpadding="0" cellspacing="0">
										<tbody>
											<tr>
												<td>
												<table border="0" cellpadding="0" cellspacing="0">
													<tbody>
														<tr>
															<td>
															<p><span style="font-size:18px">Olá, {nome}!</span></p>

															<p dir="ltr"><span style="font-size:14px;">Você deu o primeiro passo para conquistar o seu <strong>LAR </strong>dos sonhos.</span></p>

															<p dir="ltr"><span style="font-size:14px;">Para nós, lar é muito mais que um imóvel, é um <strong>Lugar de Amor e Respeito</strong>.</span></p>

															<p dir="ltr"><span style="font-size:14px;">Estamos aqui pra te ajudar nesse passo tão importante.</span></p>

															<p dir="ltr"><span style="font-size:14px;">Você validou seu <strong>Cartão VIP {key_captura}</strong> e agendou um horário para <strong>conversar com um especialista</strong> no dia <strong>{dia_visita}</strong> às <strong>{hora_visita}</strong>.</span></p>

															<p dir="ltr"><span style="font-size:14px;">Seu agendamento é <strong>VIRTUAL</strong>.&nbsp;</span></p>

															<p dir="ltr"><span style="font-size:14px;"><strong>Nosso especialista entrará em contato</strong> para te enviar o link para essa reunião.</span></p>
															<span style="font-size:14px;">Caso ainda tenha dúvidas ou queira ajuda para pensar em uma estratégia de negociação você também pode falar com um dos nossos anjos da guarda Comdono, eles estão aqui pra te apoiar.</span>

															<p dir="ltr"><span style="font-size:14px;">Não te vendemos nada por isso estamos isentos no processo, pode confiar! Se quiser um contato antes dessa reunião clique abaixo</span></p>
															</td>
														</tr>
													</tbody>
												</table>
												</td>
											</tr>
										</tbody>
									</table>

									<table border="0" cellpadding="0" cellspacing="0" style="min-width:100%" width="100%">
										<tbody>
											<tr>
												<td align="center" style="padding-top:0;padding-right:18px;padding-bottom:18px;padding-left:18px" valign="top">
												<table border="0" cellpadding="0" cellspacing="0" style="border-collapse:separate!important;border-radius:3px;background-color:#253054">
													<tbody>
														<tr>
															<td align="center" style="font-family:Helvetica;font-size:14px;padding:12px" valign="middle"><a data-saferedirecturl="https://www.google.com/url?q=https://https://dev.comdono.com/landingpage/resultado/confirmacao/liber-grupo-osrz9b/10ztb/dde894f705ea1dea08b5282777f1a126&amp;source=gmail&amp;ust=1608327983796000&amp;usg=AFQjCNGx77sqL7uhN5EG7N_wS_y_5gSZKA" href="https://api.whatsapp.com/send?phone=5561994483087&amp;text=Olá! Preciso de algumas informações." style="font-weight:bold;letter-spacing:-0.5px;line-height:100%;text-align:center;text-decoration:none;color:#ffffff" target="_blank" title="Ativar o cartão VIP">Que falar com um anjo da guarda Comdono</a></td>
														</tr>
													</tbody>
												</table>
												</td>
											</tr>
										</tbody>
									</table>

									<p dir="ltr" style="text-align: center;"><span style="font-size:14px;">Você está cada vez mais perto de realizar o seu sonho.&nbsp;</span></p>

									<p dir="ltr" style="text-align: center;"><span style="font-size:14px;">Espero que você esteja tão entusiasmado(a) quanto nós!</span></p>

									<p dir="ltr" style="text-align: center;"><span style="font-size:14px;">Temos certeza que você está dando o melhor primeiro passo para essa conquista!</span></p>

									<p dir="ltr" style="text-align: center;"><span style="font-size:14px;">Até logo!</span></p>
									</td>
								</tr>
							</tbody>
						</table>
						</td>
					</tr>
					<tr>
						<td align="center" id="m_6355739659377522657templateFooter" valign="top">
						<table align="center" border="0" cellpadding="0" cellspacing="0" style="min-width:600px;background: #253054;padding: 50px 0;" width="100%">
							<tbody>
								<tr>
									<td valign="top">
									<table border="0" cellpadding="0" cellspacing="0" style="width: 600px;margin: auto;">
										<tbody>
											<tr>
												<td style="padding-top:9px" valign="top">
												<table align="left" border="0" cellpadding="0" cellspacing="0" style="max-width:100%;min-width:100%" width="100%">
													<tbody>
														<tr>
															<td style="padding-top:0;padding-right:18px;padding-bottom:9px;padding-left:18px" valign="top">
															<div style="text-align:center"><a data-saferedirecturl="https://www.google.com/url?q=https://comdono.com/blog&amp;source=gmail&amp;ust=1608327983796000&amp;usg=AFQjCNFV5qt-L-4RziI5e4Ivtf6dgtkOMg" href="https://comdono.com/blog" target="_blank"><span style="color:#253054"><img alt="" class="CToWUd" height="25" src="/modules/newsletter/imagens/ico_blog.png" style="width:25px;height:25px;margin:0px" width="25" /></span></a><span style="color:#253054">&nbsp; &nbsp;&nbsp; </span><a data-saferedirecturl="https://www.google.com/url?q=https://api.whatsapp.com/send?phone%3D5561994483087%26text%3DOl%C3%A1!%2520Gostaria%2520de%2520receber%2520mais%2520informa%C3%A7%C3%B5es%2520sobre%2520a%2520plataforma%2520Comdono.&amp;source=gmail&amp;ust=1608327983797000&amp;usg=AFQjCNEQQb9ePLK-dm7zOMWC_GNmcDcQag" href="https://api.whatsapp.com/send?phone=5561994483087&amp;text=Olá!%20Gostaria%20de%20receber%20mais%20informações%20sobre%20a%20plataforma%20Comdono." target="_blank"><span style="color:#253054"><img alt="" class="CToWUd" height="25" src="https://comdono.s3-us-west-2.amazonaws.com/modules/newsletter/imagens/ico_whatsapp.png" style="width:25px;height:25px;margin:0px" width="25" /></span></a><span style="color:#253054">&nbsp; &nbsp;&nbsp; <a data-saferedirecturl="https://www.google.com/url?q=https://instagram.com/comdono/&amp;source=gmail&amp;ust=1608327983797000&amp;usg=AFQjCNEQXhxRCcmS3CG_0mgX4otKH78dzg" href="https://instagram.com/comdono/" target="_blank"><img alt="" class="CToWUd" height="25" src="https://comdono.s3-us-west-2.amazonaws.com/modules/newsletter/imagens/ico_instagram.png" style="width:25px;height:25px;margin:0px" width="25" /></a>&nbsp; &nbsp;&nbsp; </span><a data-saferedirecturl="https://www.google.com/url?q=https://facebook.com/comprecomdono/&amp;source=gmail&amp;ust=1608327983797000&amp;usg=AFQjCNHhFnryOJlcpn3OfK-seqlFCa6hlg" href="https://facebook.com/comprecomdono/" target="_blank"><span style="color:#253054"><img alt="" class="CToWUd" height="25" src="https://comdono.s3-us-west-2.amazonaws.com/modules/newsletter/imagens/ico_facebook.png" style="width:25px;height:25px;margin:0px" width="25" /></span></a><span style="color:#253054">&nbsp; &nbsp;&nbsp; </span><a data-saferedirecturl="https://www.google.com/url?q=https://pinterest.pt/comdono/&amp;source=gmail&amp;ust=1608327983797000&amp;usg=AFQjCNFf9mLFaTnjsoErfMECTywyI5IZPQ" href="https://pinterest.pt/comdono/" target="_blank"><span style="color:#253054"><img alt="" class="CToWUd" height="31" src="https://comdono.s3-us-west-2.amazonaws.com/modules/newsletter/imagens/ico_pinterest.png" style="border:0px;width:20px;height:24px;margin:0px" width="25" /></span></a><span style="color:#253054">&nbsp; &nbsp;&nbsp; </span><a data-saferedirecturl="https://www.google.com/url?q=https://linkedin.com/company/comdono/&amp;source=gmail&amp;ust=1608327983797000&amp;usg=AFQjCNHmD4AS2uhuWoJyD7Gb2jD6XmSqqg" href="https://linkedin.com/company/comdono/" target="_blank"><span style="color:#253054"><img alt="" class="CToWUd" height="25" src="https://comdono.s3-us-west-2.amazonaws.com/modules/newsletter/imagens/ico_linkedin.png" style="width:25px;height:25px;margin:0px" width="25" /></span></a></div>
															</td>
														</tr>
													</tbody>
												</table>
												</td>
											</tr>
										</tbody>
									</table>

									<table border="0" cellpadding="0" cellspacing="0" style="width: 600px;margin: auto;">
										<tbody>
											<tr>
												<td style="padding-top:9px" valign="top">
												<table align="left" border="0" cellpadding="0" cellspacing="0" style="max-width:100%;min-width:100%" width="100%">
													<tbody>
														<tr>
															<td style="padding:0px 18px 9px;line-height:200%" valign="top">
															<div style="text-align:center"><span style="color:#ffffff">Usamos a tecnologia e o marketing digital para<br />
															oferecer uma nova forma de comprar e vender imóveis</span><br />
															<a data-saferedirecturl="https://www.google.com/url?q=https://comdono.com/ajuda/40/politica-de-privacidade&amp;source=gmail&amp;ust=1608327983797000&amp;usg=AFQjCNHIctQuj73PIErgEAcPYSMIo6Bs1w" href="https://comdono.com/ajuda/40/politica-de-privacidade" target="_blank" title="Termos de Privacidade"><span style="color:#ffffff;text-decoration: underline;">Termos de Privacidade</span></a><span style="color:#ffffff">&nbsp;|&nbsp;</span><a data-saferedirecturl="https://www.google.com/url?q=https://api.whatsapp.com/send?phone%3D5561994483087%26text%3DOl%C3%A1!%2520Gostaria%2520de%2520receber%2520mais%2520informa%C3%A7%C3%B5es%2520sobre%2520a%2520plataforma%2520Comdono.&amp;source=gmail&amp;ust=1608327983797000&amp;usg=AFQjCNEQQb9ePLK-dm7zOMWC_GNmcDcQag" href="https://api.whatsapp.com/send?phone=5561994483087&amp;text=Olá!%20Gostaria%20de%20receber%20mais%20informações%20sobre%20a%20plataforma%20Comdono." target="_blank" title="Suporte WhatsApp"><span style="color:#ffffff;text-decoration: underline;">Suporte WhatsApp</span></a></div>
															</td>
														</tr>
													</tbody>
												</table>
												</td>
											</tr>
										</tbody>
									</table>

									<table border="0" cellpadding="0" cellspacing="0" style="width: 600px;margin: auto;">
										<tbody>
											<tr>
												<td style="padding:0px" valign="top">
												<table align="left" border="0" cellpadding="0" cellspacing="0" style="min-width:100%" width="100%">
													<tbody>
														<tr>
															<td style="padding-right:0px;padding-left:0px;padding-top:0;padding-bottom:0;text-align:center" valign="top">
															<p><a data-saferedirecturl="https://www.google.com/url?q=https://comdono.com/&amp;source=gmail&amp;ust=1608327983797000&amp;usg=AFQjCNEzLcVaJftxeNPj1X46SM5zwYtORw" href="https://comdono.com/" target="_blank"><img align="middle" alt="" class="CToWUd" height="22" src="https://comdono.s3-us-west-2.amazonaws.com/modules/newsletter/imagens/logo_comdono_white.png" style="max-width:13368px;padding-bottom:0;display:inline!important;vertical-align:bottom" width="132" /></a></p>
															</td>
														</tr>
													</tbody>
												</table>
												</td>
											</tr>
										</tbody>
									</table>
									</td>
								</tr>
							</tbody>
						</table>
						</td>
					</tr>
				</tbody>
			</table>
			</td>
		</tr>
	</tbody>
</table>
</center>

        ';
    }
}